• 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 fetch Date from DateTime in mySql

 
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

i am having a database with Column(Transaction date) which is of DateTime.
How can i fetch the records with only Date criteria.

I need to get the records on daily basis.
where "Transaction Date" is 2010-06-23 rather than time stamp appended with it.

Or is there any other option to select records on date.

Thanks in advance.

Raza!



 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would need more info to answer you propperly.

I presume you fetch some records with an SQL statement into a ResultSet object. Then you fetch data on a row by row basis, geting Date with getDate function. Date has hours and minutes, you can manualy reset them to 00:00. If you only need a formated String to print out somewhere, use SimpleDateFormat

Something like:
 
Raza Mohd
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to convert new date() object to Date object.(yyyy-MM-dd).
can you tell me how to do that.

First i convert the Date object to String ("yyyy-MM-dd")
But how to parse it to Date.

i hv got a piece of code.

 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raza Mohd, you can't format the Date object. You can only get a formatted string object, using a formatter and a date object. (unless you want to extend Date and override its toString method ... don't do it )

here's what I think you want:


Why would you use this? If you need to query for todays dates there is a current time function in mySQL CURDATE() and for current time there is CURTIME()
 
Raza Mohd
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes , I wants that.


I need to get Date As input from the user and corresponding to that date, want to search the records.
So what ever Date user inputs, depending upon that Qury will retrive the data.

So How can it be done?

thanks

 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should do it

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic