PHP Date and Time functions

Quick reference to the Date and Time functions of PHP.

Date and Time functions
Function Returns Does what
checkdate(month, day, year) Boolean Validates date
date(format [, timestamp]) String Formats a time/date
date_sun_info(time , latitude , longitude) Array Returns sunset, sunrise, and twilight times
date_sunrise(timestamp [, format [, latitude [, longitude [, zenith [, $gmt_offset]]]]]) Mixed Returns time of sunrise for day and location
date_sunset(timestamp [, format [, latitude [, longitude [, zenith [, $gmt_offset]]]]]) Mixed Returns time of sunset for day and location
getdate([timestamp]) Array Returns date/time settings for timestamp
gettimeofday([return_float]) Mixed Returns array for current time, or optional float
gmdate(format [, timestamp]) String Formats a GMT date/time
gmmktime([hour [, minute [, second [, month [, day [, year [, is_dst]]]]]]]) Integer Returns UNIX timestamp for GMT time/date. Default current date.
gmstrftime(format [, timestamp]) String Formats a GMT date/time as per current locale
localtime([timestamp[, is_associative]) Array Returns local time as array
microtime([get_as_float]) Mixed Returns microseconds from epoch. String or float.
mktime([hour [, minute [, second [, month [, day [, year [, is_dst]]]]]]]) Integer Returns UNIX timestamp for time/date. Default current date.
strftime(format [, timestamp]) String Formats a date/time as per current locale
strtotime(time [, now]) Integer Convert English datetime format to UNIX timestamp
time() Integer Returns current UNIX timestamp
Calendar functions
Function Returns Does what
easter_date([year]) Integer Returns UNIX timestamp for midnight, Easter Day. Default current year
easter_days([year [, method]) Integer Returns no. of days from March 1 to Easter Day. Default current year
FrenchToJD(month, day, year) Integer Convert from the French Republican Calendar to a Julian Day Count
GregorianToJD(month, day, year) Integer Convert from the Gregorian Calendar to a Julian Day Count
JDDayOfWeek(juliandaycount [, mode]) Mixed Returns day of week in "mode" format
JDMonthName(juliandaycount [, mode]) String Returns month in "mode" format
JDToFrench(juliandaycount) String Converts Julian Day Count to date in French Republican Calendar
JDToGregorian(juliandaycount) String Converts Julian Day Count to date in the Gregorian Calendar
jdtojewish(juliandaycount [, hebrew [, fl]) String Converts Julian Day Count to date in the Jewish Calendar
JDToJulian(juliandaycount) String Converts Julian Day Count to date in the Julian Calendar
jdtounix(juliandaycount) Integer Converts Julian Day Count to UNIX timestamp
JewishToJD(month, day, year) Integer Convert from the Jewish Calendar to a Julian Day Count
JulianToJD(month, day, year) Integer Convert from the Julian Calendar to a Julian Day Count
unixtojd(timestamp) Integer Convert a UNIX timestamp to a Julian Day Count

Date format example code:

    <?php
    $test_string = "31-12-1999 12:34:56";
    $test_timestamp = strtotime($test_string);

    $timestamp_format = "d-m-Y H:i:s"; # European 24-hour format

    # for AM/PM, use lower case "h" and append upper case "A", like this:
    # $timestamp_format = "d-m-Y h:i:s A";

    echo $test_timestamp." = ".date($timestamp_format, $test_timestamp)."\n";
    ?>
        

Time-related defalt values:

More: