Page 514 - Beginning PHP 5.3
P. 514

Part III: Using PHP in Practice
                    getdate()  accepts a timestamp and returns an associative array of date/time values corresponding to
                the supplied timestamp. The array contains the following keys:



                      Array Key      Description                          Possible Values
                        seconds       The seconds component               0 to 59

                        minutes       The minutes component               0 to 59
                        hours       The hours component, in 24 - hour format      0 to 23
                        mday       The day of the month                   1 to 31

                        wday           The day of the week as a number         0 (Sunday) to 6 (Saturday)
                        mon           The month component as a number       1 to 12
                        year       The year component as a four - digit number         Typically 1970 to 2038

                        yday       The day of the year                    0 to 365
                        weekday           The day of the week as a string       Sunday to Saturday
                        month           The month component as a string       January to December

                        0 (zero)       The timestamp                      Typically  – 2147483648 to
                                                                        2147483647


                   You can also call   getdate()  without a timestamp to return the components of the current date and time.

                   Here are a couple of   getdate()  examples:

                    // Displays “John Lennon was born on 9 October, 1940”
                    $johnLennonsBirthday = strtotime( “October 9, 1940” );
                    $d = getdate( $johnLennonsBirthday );
                    echo “John Lennon was born on “ . $d[“mday”] . “ “ . $d[“month”] . “, “ .
                    $d[“year”] . “ < br / > ”;

                    // Displays e.g. “17:31”
                    $t = getDate();

                    echo “The current time is “ . $t[“hours”] . “:” . $t[“minutes”] . “ < br / > ”;
                   If you just want to extract a single date or time component from a timestamp, you can use  idate() . This
                 function accepts two parameters: a format string and an optional timestamp. (If you omit the timestamp,
                 the current date and time are used.) The single - character format string dictates the component to return,
                 and the format in which to return it, as follows:










              476





                                                                                                      9/21/09   9:15:28 AM
          c16.indd   476
          c16.indd   476                                                                              9/21/09   9:15:28 AM
   509   510   511   512   513   514   515   516   517   518   519