note 86589 modified in book.datetime by felipe

From: Date: Fri, 24 Oct 2008 23:09:55 +0000
Subject: note 86589 modified in book.datetime by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145728@lists.php.net to get a copy of this message
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); } ?> --was-- Should you want to convert between HH:MM:SS and plain seconds like in MySQL, these functions should do the trick: 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); } http://php.net/manual/en/book.datetime.php

« previous php.notes (#145728) next »