First up, before we get into anything too complicated, let's take a quick tour of the important date and time manipulation functions that come with PHP 4.1. The simplest and most basic thing you'll want to do with PHP's date API is, obviously, get the current date and time. This is best accomplished via the getdate() function, which returns an associative array containing date and time information. Here's an example: <? // get current date information as associative array $current = getdate(); // print it print_r($current); ?>Here's what the output would look like: Array ( [seconds] => 7 [minutes] => 19 [hours] => 9 [mday] => 20 [wday] => 3 [mon] => 2 [year] => 2002 [yday] => 50 [weekday] => Wednesday [month] => February [0] => 1014176947 )This information can easily be manipulated and massaged into whatever format you like. For example, You can also give getdate() a timestamp, and have it convert that timestamp into an array for you. Consider the following example, which sends getdate() a UNIX timestamp for the date December 25 2001, and gets the information back as a much easier-to-read array: The output is: How did I create the timestamp? Flip the page to find out.
blog comments powered by Disqus |