Reputation: 3976
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.
Upvotes: 4
Views: 7787
Reputation: 5006
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;
Upvotes: 8
Reputation: 1379
You should try to get the difference between these two values (e.g. as a timestamp) and format the date in you application. You can get the current timestamp with NOW(). If you want MySQL to format your data you should take a look at the manual. There are several functions for that.
Upvotes: 3