Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get remaining days, hours and minutes using mySql

Tags:

mysql

I am stuck in getting the remaining days, hours and minutes between two dates in mySql.

I have an expiry date and I want to compare it with current DateTime and want to get days, hours and minutes.

like image 302
Sami Avatar asked Dec 21 '22 07:12

Sami


1 Answers

This stackoverflow link may help you. There is many way to calculate difference between two dates and your are not oblige to do this in full SQL.

[EDIT]

I ve found a solution in SQL...

SELECT  TIMESTAMPDIFF(DAY,NOW(),'2012-01-01') AS DAY,
        TIMESTAMPDIFF(HOUR,NOW(),'2012-01-01')-TIMESTAMPDIFF(DAY,NOW(),'2012-01-01')*24 AS HOUR,
        TIMESTAMPDIFF(MINUTE,NOW(),'2012-01-01')-TIMESTAMPDIFF(HOUR,NOW(),'2012-01-01')*60 AS MINUTE;
like image 198
Fred Avatar answered Jan 13 '23 11:01

Fred