File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes mysql - get time interval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql - get time interval" Watch "mysql - get time interval" New topic
Author

mysql - get time interval

ian dwyer
Greenhorn

Joined: Nov 28, 2004
Posts: 1
hello - this is probably pretty simple, but i was wondering if anyone had seen any examples of how to select something from a database based on a time interval.

for example, i have a number of records in a database, and I want to be able to pull all the ones out that have been created, say, less than one hour from the present time.

what is the best time/date format to stamp these things and what are the comparison methods like?

thanks!
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi Ian, welcome to JavaRanch.

This depends on the database you are using, and whether it supports arithmatic operators on date/time values, or has special methods to use with data/time.

In Oracle, you can just subtract two Dates, and it gives you the number of days(or the fraction of a day) between the two, which you can use in specifying your conditions.

The best place to start is the documentation for the database you are using.

Cheers


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql - get time interval
 
Similar Threads
auto-save from data when session times out
refresh a JPanel automatically with time
Converting millisecs to hour, minute, seconds.
database equivalent for XML time
Duplicate Timers in JBOSS