This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to fetch Date from DateTime in mySql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to fetch Date from DateTime in mySql" Watch "How to fetch Date from DateTime in mySql" New topic
Author

How to fetch Date from DateTime in mySql

Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

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!




Good luck!!
A small leak can sink a Gigantic ship.>
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
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:


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

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

Joined: Sep 16, 2008
Posts: 241
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

Joined: Jan 20, 2010
Posts: 247

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

Joined: Sep 16, 2008
Posts: 241
This should do it

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to fetch Date from DateTime in mySql
 
Similar Threads
How to fetch Date Field from excel sheet in Java
search based on from and TO date
Manipulation Date Time In RMS
ClassCaseException
String to Date conversion