faqts : Computers : Programming : Languages : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

62 of 81 people (77%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I get today's date and time in PHP?
How can I determine the current time in PHP?

May 7th, 2004 15:38
Philip Olson, Nathan Wallace, Sander Pilon


Check out the date(), time(), and mktime() functions here:
    http://www.php.net/manual/en/function.date.php
    http://www.php.net/manual/en/function.time.php
    http://www.php.net/manual/en/function.mktime.php
Leave the second argument in the date() function empty to use today's
date and time.  The date() documentation lists many arguments (in the
form of case sensitive letters) that yield days, months, etc. when used.
 For example:
<?php
    echo date('Y m d');
?>
Will return something like:
    2004 12 25
Because:
Y = A full numeric representation of a year, 4 digits
m = Numeric representation of a month, with leading zeros
d = Day of the month, 2 digits with leading zeros
See the date() documentation for more details and examples.  Also, see
the manual chapter titled 'Date and time functions' for more information:
    http://www.php.net/manual/en/ref.datetime.php