View Single Post
  #3 (permalink)  
Old October 25th, 2012, 06:05 PM
ciderpunx ciderpunx is offline
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by internetpirate11 View Post
ok i have data stored in my database field is datetime/timestamp.
so what i want is, i want data to be displayed which is older than 24 hours only.

SO how could i write query for that??
Code:
SELECT * FROM table WHERE datetime <(UNIX_TIMESTAMP(NOW()) - 24*60*60);
A UNIX timestamp is a count of seconds since 1 Jan 1970 24*60*60 is the number of seconds in 24 hours.

You can also write (IIRC):

Code:
WHERE datediff(hh, datetime, NOW()) < 24
__________________
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote