• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to generate sql date

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String day = request.getParameter("day");
String month = request.getParameter("month");
String year = request.getParameter("xage");
how do I generate the sql date from these three integers
int d = Integer.parseInt(day);
int m = Integer.parseInt(month);
int y = Integer.parseInt(year);
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The deprecated Date(y, m, d) constructor sure was a lot easier to use if you don't need i18n (internationalisation).
- Peter
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The deprecated Date(y, m, d) constructor sure was a lot easier to use if you don't need i18n (internationalisation).
- Peter


I know this post is OLD, but I just needed to say "YOU CAN SAY THAT AGAIN!"
I started my JDBC Date Fun trying to use DateFormat, but all of the methods return java.util.Date, not java.sql.Date. To the best of my knowledge (PLEASE correct me if anyone knows better) there is NO way (other than something similar to the above) to simply convert between java.util.Date and java.sql.Date. What a hassle.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if this is helpful to you, but one way to convert java.util.Date to java.sql.Date is :
new java.sql.Date(utilDate.getTime())
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Ravindra, you can construct a sql Date by -
java.sql.Date.valueOf(s)
where s = a string in JDBC date escape format, "yyyy-mm-dd"
 
Dave Soto
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for the getTime() recommendation. That works wonderfully.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,
Actually i am using calender class and Timestamp class adn storing the date with time in the sql database , but the thing is while retreiving the date , the second part of the time is not displaying , so can u suggest me how to get the date along wiht time along with seconds .
Thanks in advance,
bhaskar
[This message has been edited by bhaskar nagaraja (edited October 16, 2001).]
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use the resultset.getDate() method when retrieving value, use resultset.getTimestamp()
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic