Get remaining days, hours and minutes using 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.
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;
You should try to get the difference between these two values (eg 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.
链接地址: http://www.djcxy.com/p/58970.html