Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query to only exclude data of last 24 hours?

Tags:

datetime

mysql

I have the following data:

Table Name: NODE
NID | Name | Date
001 | One  | 1252587739

Date is a unix timestamp. I need a query, whereby I can select only the nodes who's "Date" is older than 24 hours. Something like this:

SELECT * FROM NODE WHERE Date < NOW() - SOMETHING
  1. Anybody know how to do this?
  2. Does the NOW() - SOMETHING part take into account that the date is stored as a unix timestamp?
like image 930
coderama Avatar asked Dec 01 '25 01:12

coderama


1 Answers

Unix timestamp is in seconds. This works with MySQL:

SELECT * FROM NODE WHERE Date < (UNIX_TIMESTAMP(NOW()) - 24*60*60)
like image 70
Carlos Gutiérrez Avatar answered Dec 03 '25 18:12

Carlos Gutiérrez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!