Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Format problem MySQL

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have got a little problem,

in my database table i'm storing date in the following format 'Mon Apr 16 12:55:32 IST 2007' the datatype of the field is varchar.

and now i want to list all the record of current date.

how do i do it ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jigar,
I assume it is too late to use a date type at this point?

You have two choices of approach:
1) Use a database specific to_date() function to convert the varchar to a date in the query. For large tables, this could be slow because the function will be called on every row.
2) Build the date as a string in Java and add something like this to your where clause: "where field like '%Apr 16%2007'"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic