Wednesday 23 May 2012

Find the timestamp difference/two date difference in terms of day, hour, minute, second format using MySQL query

--
Find the timestamp difference/two date difference in terms of day, hour, minute, second format in MySQL query.
// MySQL convert timediff output to day, hour, minute, second format
SELECT 
CONCAT(TIMESTAMPDIFF(day,u.date_created, NOW()), 'Days ', 
 MOD( TIMESTAMPDIFF(hour,u.date_created, NOW()), 24), 'Hrs ',
 MOD( TIMESTAMPDIFF(minute,u.date_created, NOW()), 60), 'Mins ',
 MOD( TIMESTAMPDIFF(second,u.date_created, NOW()), 60), 'Secs ') as days_ago

/* OUTPUT */
1 day 23 hr 10 min 12 sec 

--

No comments:

Post a Comment

Please post any queries and comments here.