Created
February 3, 2018 11:42
-
-
Save OkoyaUsman/8e2e1224cc3fb1f2c82c0d383ad67240 to your computer and use it in GitHub Desktop.
PHP Function to Convert Seconds into Years, Months, Days, Hours, Minutes and Seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function convertSecToTime($sec){ | |
$date1 = new DateTime("@0"); //starting seconds | |
$date2 = new DateTime("@$sec"); // ending seconds | |
$interval = date_diff($date1, $date2); //the time difference | |
return $interval->format('%y Years, %m months, %d days, %h hours, %i minutes and %s seconds'); // convert into Years, Months, Days, Hours, Minutes and Seconds | |
} | |
echo convertSecToTime(246395678); | |
//OUTPUT: 7 Years, 9 months, 21 days, 19 hours, 14 minutes and 38 seconds | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment