spacer.png, 0 kB
spacer.png, 0 kB
Home arrow PHP arrow PHP: date and time
PHP: date and time PDF Print E-mail

PHP date() function is one of the fastest and simples way to format date and time and then use it inside your scripts.
The string input function parameter accept special characters (listed here below) replaced by PHP with the date and time value (depending on the values). 
  • a - "am" or "pm"
  • A - "AM" or "PM"
  • B - Swatch Internet Time
  • d - day of the month, 2 digits with 0; "01" - "31"
  • D - day of the week, text mode, 3 letters; "Fri"
  • F - month, text, long; "January"
  • g - hour, 12 hour format w/o leading zeros; "1" - "12"
  • G - hour, 24 hour format w/o leading zeros; "0" - "23"
  • h - hour, 12 hour format; "01" - "12"
  • H - hour, 24 hour format; "00" - "23"
  • i - minutes; "00" - "59"
  • I - "1" if the date is in daylight saving time, "0" the opposite case
  • j - day of the month w/o leading zeros; "1" - "31"
  • l - day of the week, text mode, long; "Friday"
  • L - Whether it's a leap year; "0" or "1"
  • m - month; "01" - "12"
  • M - month, text mode, 3 letters; "Jan"
  • n - month w/o leading zeroes; "1" to "12"
  • O - difference to Greenwich time (GMT) in hours; "+0200"
  • r - RFC 822 formatted date; "Thu, 21 Dec 2000 16:01:07 +0200"
  • s - seconds; "00" to "59"
  • S - english ordinal suffix (the day of the month), 2 characters, "th", "nd"
  • t - number of days in the given month; "28" / "31"
  • T - timezone abbreviation; "MDT"
  • U - seconds since the Unix Epoch
  • w - day of the week, numeric, "0" (Sunday) a "6" (Saturday)
  • W - ISO-8601 week number of year, (weeks starting on Monday)
  • Y - year, 4 digits; "1999"
  • y - year, 2 digits; "99"
  • z - day of the year; "0" to "365"
  • Z - timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive (-43200 through 50400)
Unrecognized characters in the format string will be printed as-is. To print instead the above characters as-is you should use the escape backslash '\' character.
echo date("l \\t\h\e jS"); // output: 'Saturday the 8th'
You can use date() function in combination with mktime() to manage date in future or past.
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
$lastmonth = mktime(0,0,0,date("m")-1,date("d"),date("Y"));
$nextyear = mktime(0,0,0,date("m"),date("d"),date("Y")+1);
Last Updated ( marted́, 04 dicembre 2007 )
 
< Prev   Next >
spacer.png, 0 kB
spacer.png, 0 kB
spacer.png, 0 kB