php - MySQL second to formatted date time -
how convert second formatted date time in mysql? have query date difference in second. i.e
select timestampdiff(second, '2012-06-03 13:13:55', '2012-06-06 15:20:18') sec
now need convert seconds in date time in sql. possible? or there function in mysql datetime fields difference formatted option
select datediff('%m %d, %y %h...', '2012-06-03 13:13:55', '2012-06-06 15:20:18') sec
so expected result 1 mon 5 day 13 hour 3 sec
this seems work
select timestampdiff(second, '2012-06-03 13:13:55', '2012-06-06 15:20:18') secs, timestampdiff(minute, '2012-06-03 13:13:55', '2012-06-06 15:20:18') mins, timestampdiff(hour, '2012-06-03 13:13:55', '2012-06-06 15:20:18') hours, timestampdiff(day, '2012-06-03 13:13:55', '2012-06-06 15:20:18') days, timestampdiff(month, '2012-06-03 13:13:55', '2012-06-06 15:20:18') months, timestampdiff(year, '2012-06-03 13:13:55', '2012-06-06 15:20:18') years
giving result row
secs mins hours days months years 266783 4446 74 3 0 0
you can whatever results
you use seconds result column create output using php :-
<?php // of course result set not hard coded value $secs = 266783; $days = date('d', $secs); $secs -= $days*24*60*60; $hours = date('h', $secs); $secs -= $hours*60*60; $mins = date('m', $secs); $secs -= $mins*60; $seconds = date('s', $secs); echo sprintf('%d days %d hours %d minutes %d seconds', $days, $hours, $mins, $seconds );
this output
4 days 2 hours 12 minutes 23 seconds
Comments
Post a Comment