Dates and Times

[Index]

Dates and times occur time and again in web applications. Not only do we want to know what the local time is, but we will need to timestamp any thing being put into our Data bases. Complicating matters are the various time format's used arouund the world. The international yyyy-mm-dd format is the most logical. The dd/mm/yyyy is also logical, and the USA is alone in it's illogical mm/dd/yy format (I dare anyone to defend it!). However because the '600lb. Gorilla' rule applies just as much here as elsewhere, this is the format that has the widest use!

Luckily PHP makes it easy for us to write dates in any format!

UNIX Timestamps

Functions that return Times and Dates

Formatting the Times and Dates

Generating random values with microtime

<?
 // seed with microseconds
function make_seed() {
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);
}
mt_srand(make_seed());
$randval = mt_rand(0,11);
//srand(make_seed());
//$randval = //rand(0,11);

©Frank Boumphrey 2001