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

How to fetch Date from DateTime in mySql

 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • 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!



 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • 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
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java MyEclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
This should do it

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic