Re: A better way to do this in php???

From: Date: Thu, 21 Oct 2004 14:29:25 +0000
Subject: Re: A better way to do this in php???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-199994@lists.php.net to get a copy of this message
Here's a one liner that gives the minutes since midnight: floor( (time()-mktime(0,0,0, date( 'm' ), date( 'd' ), date( 'Y' )))/60); Both time() and mktime() return the seconds since epoch. Time is based on current time, and the mktime parameters base it on midnight. A simple subtraction gives you the seconds since midnight. Divide by 60 to get minutes and use floor() to drop any extra "seconds". On Oct 20, 2004, at 6:45 PM, bclem@imaginative-enterprises.com wrote:
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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577


« previous php.general (#199994) next »