Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date difference in SQL

Tags:

date

mysql

How can I get the number of second between NOW() and a date in the database.

Thanks.

like image 315
VisaMasterCard Avatar asked Jun 17 '26 10:06

VisaMasterCard


2 Answers

Use the TIMESTAMPDIFF function. (the TIMEDIFF function has a upper limit of 838:59:59)

SELECT TIMESTAMPDIFF(SECOND, DateColumn, NOW()) As Seconds
FROM table
like image 96
The Scrum Meister Avatar answered Jun 20 '26 01:06

The Scrum Meister


Try this:

SELECT TIME_TO_SEC(TIMEDIFF(Now(), yourDateTime)) From Table;
  • MySQL: Now()
  • MySQL: TimeDiff-Function
  • MySQL: TIME_TO_SEC-Function
like image 34
Tim Schmelter Avatar answered Jun 19 '26 23:06

Tim Schmelter



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!