• 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

Convert to timestamp yyyy-MM-dd hh:mm:ss a

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi;
I have a jsp and passing start_date as a string with this format
input string 2006-01-02 03:04:00
database timestamp: 2006-01-02 03:04:00

in the database, the java method expected Date '2006-01-02 03:04:00' as parameter . In the SQL it search like "select * from table where date1 >= '2006-01-01 12:13:00' and date2 <= '2007-01-02 12:13:00'"

Here what I do:


Many thanks for your help. Regards
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your input string does not have the am/pm marker (aa) that your date format has.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carol: i fixed it,
but for example on my jsp i enter 2007-01-02 15:00:00
i ran through my code [see previous post], the output string is
<b>Tue Jan 02 15:00:00 </b> not the format <b> "yyyy-MM-dd hh:mm:ss" </b> as I wanted? Any ideas how to fix this
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please help,
this is what I have so far,
input date from jsp: 2007-02-03 09:00:00 as a string
I need to convert this to a java.util.Date format yyyy-MM-dd hh:mm:ss


Greatly appreciated if you can help thanks much
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but I'm not following your problem.

You've got a String representing a date. (inputstring)
You turn it into a Date. (d1)
You turn it back into the String you started with. (mydt)
Now you cannot turn it back into a date? (what is wrong with d1?)
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carol: sorry for the confusing:
Let me try again:

On the jsp: there are two seperate field: Date, and Hour, User can enter date with format yyyy-MM-dd and Hour hh:mm:ss

When I got this two fields, i need to somehow reformat to be the whole thing yyyy-MM-dd hh:mm:ss,

I try to concate the string, but it won't work



So from the above code , you are saying that I just using d1 to passing into the method that epxect Date
private String getSomething (Date myDate) // passing d1 in here, but I got stuck at the hour,minute,seconde.

any ideas or hints. Greatly appreciated THNkS
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try printing out your intermediate strings or use a debugger to look at what you are doing.

It looks like you are missing the space between date and time components when you concatenate.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of modifying the Java code why dont you use the to_date/to_char functions in SQL? Its much simpler that way.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aditya Kumar:
Instead of modifying the Java code why dont you use the to_date/to_char functions in SQL? Its much simpler that way.



...unless of course you change databases to one that does not support these functions (since they are not standard SQL).
 
Aditya Kumar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Paul

I hope I was not completely wrong there.
 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correct the error line to:
java.util.Date d1 = sdf.parse(inputdate + " " + inputhr);
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for everyone input. regards,i will try it out
 
reply
    Bookmark Topic Watch Topic
  • New Topic