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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxxxxxxxxx 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux