<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Date Formats</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetime.formats.time.html">Time Formats</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetime.formats.compound.html">Compound Formats</a></div> <div class="up"><a href="datetime.formats.html">Supported Date and Time Formats</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="datetime.formats.date" class="section"> <h2 class="title">Date Formats</h2> <p class="para"> This page describes the different date formats that the <span class="function"><a href="function.strtotime.html" class="function">strtotime()</a></span>, <a href="class.datetime.html" class="classname">DateTime</a> and <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span> parser understands. </p> <table class="doctable table"> <caption><strong>Used Symbols</strong></caption> <thead> <tr> <th>Description</th> <th>Format</th> <th>Examples</th> </tr> </thead> <tbody class="tbody"> <tr> <td><em>daysuf</em></td> <td>"st" | "nd" | "rd" | "th"</td> <td class="empty"> </td> </tr> <tr> <td><em>dd</em></td> <td>([0-2]?[0-9] | "3"[01]) <em>daysuf</em>?</td> <td>"7th", "22nd", "31"</td> </tr> <tr> <td><em>DD</em></td> <td>"0" [0-9] | [1-2][0-9] | "3" [01]</td> <td>"07", "31"</td> </tr> <tr> <td><em>m</em></td> <td>'january' | 'february' | 'march' | 'april' | 'may' | 'june' | 'july' | 'august' | 'september' | 'october' | 'november' | 'december' | 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec' | "I" | "II" | "III" | "IV" | "V" | "VI" | "VII" | "VIII" | "IX" | "X" | "XI" | "XII"</td> <td class="empty"> </td> </tr> <tr> <td><em>M</em></td> <td>'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec'</td> <td class="empty"> </td> </tr> <tr> <td><em>mm</em></td> <td>"0"? [0-9] | "1"[0-2]</td> <td>"0", "04", "7", "12"</td> </tr> <tr> <td><em>MM</em></td> <td>"0" [0-9] | "1"[0-2]</td> <td>"00", "04", "07", "12"</td> </tr> <tr> <td><em>y</em></td> <td>[0-9]{1,4}</td> <td>"00", "78", "08", "8", "2008"</td> </tr> <tr> <td><em>yy</em></td> <td>[0-9]{2}</td> <td>"00", "08", "78"</td> </tr> <tr> <td><em>YY</em></td> <td>[0-9]{4}</td> <td>"2000", "2008", "1978"</td> </tr> </tbody> </table> <table class="doctable table"> <caption><strong>Localized Notations</strong></caption> <thead> <tr> <th>Description</th> <th>Format</th> <th>Examples</th> </tr> </thead> <tbody class="tbody"> <tr> <td>American month and day</td> <td><em>mm</em> "/" <em>dd</em></td> <td>"5/12", "10/27"</td> </tr> <tr> <td>American month, day and year</td> <td><em>mm</em> "/" <em>dd</em> "/" <em>y</em></td> <td>"12/22/78", "1/17/2006", "1/17/6"</td> </tr> <tr> <td>Four digit year, month and day with slashes</td> <td><em>YY</em> "/" <em>mm</em> "/" <em>dd</em></td> <td>"2008/6/30", "1978/12/22"</td> </tr> <tr> <td>Four digit year and month (GNU)</td> <td><em>YY</em> "-" <em>mm</em></td> <td>"2008-6", "2008-06", "1978-12"</td> </tr> <tr> <td>Year, month and day with dashes</td> <td><em>y</em> "-" <em>mm</em> "-" <em>dd</em></td> <td>"2008-6-30", "78-12-22", "8-6-21"</td> </tr> <tr> <td>Day, month and four digit year, with dots, tabs or dashes</td> <td><em>dd</em> [.\t-] <em>mm</em> [.-] <em>YY</em></td> <td>"30-6-2008", "22.12\t1978"</td> </tr> <tr> <td>Day, month and two digit year, with dots or tabs</td> <td><em>dd</em> [.\t] <em>mm</em> "." <em>yy</em></td> <td>"30.6.08", "22\t12\t78"</td> </tr> <tr> <td>Day, textual month and year</td> <td><em>dd</em> ([ \t.-])* <em>m</em> ([ \t.-])* <em>y</em></td> <td>"30-June 2008", "22DEC78", "14 III 1879"</td> </tr> <tr> <td>Textual month and four digit year (Day reset to 1)</td> <td><em>m</em> ([ \t.-])* <em>YY</em></td> <td>"June 2008", "DEC1978", "March 1879"</td> </tr> <tr> <td>Four digit year and textual month (Day reset to 1)</td> <td><em>YY</em> ([ \t.-])* <em>m</em></td> <td>"2008 June", "1978-XII", "1879.MArCH"</td> </tr> <tr> <td>Textual month, day and year</td> <td><em>m</em> ([ .\t-])* <em>dd</em> [,.stndrh\t ]+ <em>y</em></td> <td>"July 1st, 2008", "April 17, 1790", "May.9,78"</td> </tr> <tr> <td>Textual month and day</td> <td><em>m</em> ([ .\t-])* <em>dd</em> [,.stndrh\t ]*</td> <td>"July 1st,", "Apr 17", "May.9"</td> </tr> <tr> <td>Day and textual month</td> <td><em>d</em> ([ .\t-])* <em>m</em></td> <td>"1 July", "17 Apr", "9.May"</td> </tr> <tr> <td>Month abbreviation, day and year</td> <td><em>M</em> "-" <em>DD</em> "-" <em>y</em></td> <td>"May-09-78", "Apr-17-1790"</td> </tr> <tr> <td>Year, month abbreviation and day</td> <td><em>y</em> "-" <em>M</em> "-" <em>DD</em></td> <td>"78-Dec-22", "1814-MAY-17"</td> </tr> <tr> <td>Year (and just the year)</td> <td><em>YY</em></td> <td>"1978", "2008"</td> </tr> <tr> <td>Textual month (and just the month)</td> <td><em>m</em></td> <td>"March", "jun", "DEC"</td> </tr> </tbody> </table> <table class="doctable table"> <caption><strong>ISO8601 Notations</strong></caption> <thead> <tr> <th>Description</th> <th>Format</th> <th>Examples</th> </tr> </thead> <tbody class="tbody"> <tr> <td>Eight digit year, month and day</td> <td><em>YY</em> <em>MM</em> <em>DD</em></td> <td>"15810726", "19780417", "18140517"</td> </tr> <tr> <td>Four digit year, month and day with slashes</td> <td><em>YY</em> "/" <em>MM</em> "/" <em>DD</em></td> <td>"2008/06/30", "1978/12/22"</td> </tr> <tr> <td>Two digit year, month and day with dashes</td> <td><em>yy</em> "-" <em>MM</em> "-" <em>DD</em></td> <td>"08-06-30", "78-12-22"</td> </tr> <tr> <td>Four digit year with optional sign, month and day</td> <td>[+-]? <em>YY</em> "-" <em>MM</em> "-" <em>DD</em></td> <td>"-0002-07-26", "+1978-04-17", "1814-05-17"</td> </tr> </tbody> </table> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> For the <em>y</em> and <em>yy</em> formats, years below 100 are handled in a special way when the <em>y</em> or <em>yy</em> symbol is used. If the year falls in the range 0 (inclusive) to 69 (inclusive), 2000 is added. If the year falls in the range 70 (inclusive) to 99 (inclusive) then 1900 is added. This means that "00-01-01" is interpreted as "2000-01-01". </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The "Day, month and two digit year, with dots or tabs" format (<em>dd</em> [.\t] <em>mm</em> "." <em>yy</em>) only works for the year values 61 (inclusive) to 99 (inclusive) - outside those years the <em class="emphasis">time format</em> "<em>HH</em> [.:] <em>MM</em> [.:] <em>SS</em>" has precedence. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The "Year (and just the year)" format only works if a time string has already been found -- otherwise this format is recognised as <em>HH</em> <em>MM</em>. </p> </p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> It is possible to over- and underflow the <em>dd</em> and <em>DD</em> format. Day 0 means the last day of previous month, whereas overflows count into the next month. This makes "2008-08-00" equivalent to "2008-07-31" and "2008-06-31" equivalent to "2008-07-01" (June only has 30 days). </p> <p class="para"> It is also possible to underflow the <em>mm</em> and <em>MM</em> formats with the value 0. A month value of 0 means December of the previous year. As example "2008-00-22" is equivalent to "2007-12-22". </p> <p class="para"> If you combine the previous two facts and underflow both the day and the month, the following happens: "2008-00-00" first gets converted to "2007-12-00" which then gets converted to "2007-11-30". This also happens with the string "0000-00-00", which gets transformed into "-0001-11-30" (the year -1 in the ISO 8601 calendar, which is 2 BC in the proleptic Gregorian calendar). </p> </p></blockquote> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetime.formats.time.html">Time Formats</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetime.formats.compound.html">Compound Formats</a></div> <div class="up"><a href="datetime.formats.html">Supported Date and Time Formats</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>