• 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

mysql - get time interval

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Yes, my master! Here is the tiny ad you asked for:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic