Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Check if now Timestamp is greater than expired Timestamp

I want to Check if the Timestamp of now is greater than my Expired Timestamp:

id  |  created_timestamp  |   expired_timestamp
1   |     1542570971      |   1542743771

I have tried:

SELECT * FROM premium WHERE expired_timestamp >= now();

Nothing works :/

like image 603
Elyas Nice Avatar asked Dec 22 '25 22:12

Elyas Nice


2 Answers

You simply need to use UNIX_TIMESTAMP() function:

SELECT * FROM premium 
WHERE expired_timestamp >= UNIX_TIMESTAMP();

NOW() function returns current datetime in YYYY-MM-DD HH:MM:SS format. While Unix_Timestamp() function will return the current datetime's unix timestamp value (unsigned integer). You need to use the latter in your case.

like image 83
Madhur Bhaiya Avatar answered Dec 24 '25 10:12

Madhur Bhaiya


I think you want UNIX_TIMESTAMP():

SELECT *
FROM premium
WHERE expired_timestamp >= UNIX_TIMETAMP();
like image 23
Gordon Linoff Avatar answered Dec 24 '25 12:12

Gordon Linoff