• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

sql.Date problem

Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folowing is my senario,
1) I am reading Form input text field 'Date' as
String str1=request.getParameter("Date");
which accepts input in yyyymmdd format.
eg: str1="20020422"
2) I want to store this Date into table with column type Date
AssignedOn Date
3)I am using PrepareStatement to insert values into table.
problem here is Datevar must be sql.Date type
4)I am converting String to sql Date as
Long l1=new Long(str1);
long l2=l1.longValue();
Date d1= new Date(l2);
System.out.println("long value:"+ l2);
System.out.println("Date:"+ d1.toString());
First print prints:long value:4122002
Second prints : Date:1969-12-31
Why it is taking wired value?
I even try by giving String in 'mmddyyyy' format
it prints 1969-12-31.
what's happening here?
Please let me any one knows any other way to store Date value(which is from htnl form) in table.
[ April 22, 2002: Message edited by: padma patil ]
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The constructor for Date that takes a long as an argument creates a date based on the number of milliseconds since January 1 1970 at 00:00:00 not the date itself.
To do what you are trying to do why ot just take the date you get and add the dashes (-) into it separate the yyyy-mm-dd and then just store it that way?
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic