note 86589 deleted from book.datetime by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:33:15 +0000 |
| Subject: | note 86589 deleted from book.datetime by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210799@lists.php.net to get a copy of this message | ||
Note Submitter: zoe at monkeehouse dot com
----
Should you want to convert between HH:MM:SS and plain seconds like in MySQL, these functions should
do the trick:
<?php
function time_to_sec($time) {
$hours = substr($time, 0, -6);
$minutes = substr($time, -5, 2);
$seconds = substr($time, -2);
return $hours * 3600 + $minutes * 60 + $seconds;
}
function sec_to_time($seconds) {
$hours = floor($seconds / 3600);
$minutes = floor($seconds % 3600 / 60);
$seconds = $seconds % 60;
return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
}
?>