A better way to do this in php???
| From: | bclem at imaginative-enterprises dot com | Date: | Wed, 20 Oct 2004 22:45:11 +0000 |
| Subject: | A better way to do this in php??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-199952@lists.php.net to get a copy of this message | ||
I need to find the exact time of day using "minutes since midnight".
What is the easiest and/or better way to do this in php?
This is how I'm doing it now.
// $iMinutes is the total number of minutes since midnight/12am
// 0 = midnight/12am
// 1439 = 11:59pm
$iMinutes = 1230;
if ($iMinutes < 0 || $iMinutes > 1439) {
$restime = "??:??";
} else {
$iHour = $iMinutes / 60;
$iMins = ($iMinutes - (60*$iHour)) % 60;
if ($iHour <= 12) {
$restime .= $iHour . ":";
} else {
$restime .= $iHour-12 . ":";
}
if ($iMins < 10) {
$restime .= "0" . $iMins;
} else {
$restime .= $iMins;
}
if ($iHour < 12) {
$restime .= " a.m.";
} else if ($iHour==12 && $iMins==0) {
$restime .= " noon";
} else {
$restime .= " pm";
}
}
Thanks, Brent
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.