<HTML ><HEAD ><TITLE >strftime</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Date and Time functions" HREF="ref.datetime.html"><LINK REL="PREVIOUS" TITLE="mktime" HREF="function.mktime.html"><LINK REL="NEXT" TITLE="strtotime" HREF="function.strtotime.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.mktime.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.strtotime.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.strftime" ></A >strftime</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN16995" ></A ><P > (PHP 3, PHP 4 )</P >strftime -- Format a local time/date according to locale settings </DIV ><DIV CLASS="refsect1" ><A NAME="AEN16998" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >strftime</B > ( string format [, int timestamp])<BR ></BR ><P > Returns a string formatted according to the given format string using the given <TT CLASS="parameter" ><I >timestamp</I ></TT > or the current local time if no timestamp is given. Month and weekday names and other language dependent strings respect the current locale set with <A HREF="function.setlocale.html" ><B CLASS="function" >setlocale()</B ></A >. </P ><P > The following conversion specifiers are recognized in the format string: <P ></P ><UL ><LI ><P > %a - abbreviated weekday name according to the current locale </P ></LI ><LI ><P > %A - full weekday name according to the current locale </P ></LI ><LI ><P > %b - abbreviated month name according to the current locale </P ></LI ><LI ><P > %B - full month name according to the current locale </P ></LI ><LI ><P > %c - preferred date and time representation for the current locale </P ></LI ><LI ><P > %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) </P ></LI ><LI ><P > %d - day of the month as a decimal number (range 01 to 31) </P ></LI ><LI ><P > %D - same as %m/%d/%y </P ></LI ><LI ><P > %e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31') </P ></LI ><LI ><P > %g - like %G, but without the century. </P ></LI ><LI ><P > %G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead. </P ></LI ><LI ><P > %h - same as %b </P ></LI ><LI ><P > %H - hour as a decimal number using a 24-hour clock (range 00 to 23) </P ></LI ><LI ><P > %I - hour as a decimal number using a 12-hour clock (range 01 to 12) </P ></LI ><LI ><P > %j - day of the year as a decimal number (range 001 to 366) </P ></LI ><LI ><P > %m - month as a decimal number (range 01 to 12) </P ></LI ><LI ><P > %M - minute as a decimal number </P ></LI ><LI ><P > %n - newline character </P ></LI ><LI ><P > %p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale </P ></LI ><LI ><P > %r - time in a.m. and p.m. notation </P ></LI ><LI ><P > %R - time in 24 hour notation </P ></LI ><LI ><P > %S - second as a decimal number </P ></LI ><LI ><P > %t - tab character </P ></LI ><LI ><P > %T - current time, equal to %H:%M:%S </P ></LI ><LI ><P > %u - weekday as a decimal number [1,7], with 1 representing Monday </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Sun Solaris seems to start with Sunday as 1 although ISO 9889:1999 (the current C standard) clearly specifies that it should be Monday. </P ></TD ></TR ></TABLE ></DIV ></LI ><LI ><P > %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week </P ></LI ><LI ><P > %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.) </P ></LI ><LI ><P > %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week </P ></LI ><LI ><P > %w - day of the week as a decimal, Sunday being 0 </P ></LI ><LI ><P > %x - preferred date representation for the current locale without the time </P ></LI ><LI ><P > %X - preferred time representation for the current locale without the date </P ></LI ><LI ><P > %y - year as a decimal number without a century (range 00 to 99) </P ></LI ><LI ><P > %Y - year as a decimal number including the century </P ></LI ><LI ><P > %Z - time zone or name or abbreviation </P ></LI ><LI ><P > %% - a literal `%' character </P ></LI ></UL > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's <B CLASS="function" >strftime()</B >. This means that e.g. %e, %T, %R and %D (there might be more) will not work on Windows. </P ></BLOCKQUOTE ></DIV > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN17089" ></A ><P ><B >Example 1. <B CLASS="function" >strftime()</B > locale examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >setlocale (LC_TIME, "C"); print (strftime ("%A in Finnish is ")); setlocale (LC_TIME, "fi_FI"); print (strftime ("%A, in French ")); setlocale (LC_TIME, "fr_FR"); print (strftime ("%A and in German ")); setlocale (LC_TIME, "de_DE"); print (strftime ("%A.\n"));</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > This example works if you have the respective locales installed in your system. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > %G and %V, which are based on ISO 8601:1988 week numbers can give unexpected (albiet correct) results if the numbering system is not thoroughly understood. See %V above and example below. </P ></BLOCKQUOTE ></DIV > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN17095" ></A ><P ><B >Example 2. ISO 8601:1988 week number example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php /* December 2002 / January 2003 ISOWk M Tu W Thu F Sa Su ----- ---------------------------- 51 16 17 18 19 20 21 22 52 23 24 25 26 27 28 29 1 30 31 1 2 3 4 5 2 6 7 8 9 10 11 12 3 13 14 15 16 17 18 19 */ // Outputs: 12/28/2002 - %V,%G,%Y = 52,2002,2002 print "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/28/2002")) . "\n"; // Outputs: 12/30/2002 - %V,%G,%Y = 1,2003,2002 print "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/30/2002")) . "\n"; // Outputs: 1/3/2003 - %V,%G,%Y = 1,2003,2003 print "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n"; // Outputs: 1/10/2003 - %V,%G,%Y = 2,2003,2003 print "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n"; /* December 2004 / January 2005 ISOWk M Tu W Thu F Sa Su ----- ---------------------------- 51 13 14 15 16 17 18 19 52 20 21 22 23 24 25 26 53 27 28 29 30 31 1 2 1 3 4 5 6 7 8 9 2 10 11 12 13 14 15 16 */ // Outputs: 12/23/2004 - %V,%G,%Y = 52,2004,2004 print "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n"; // Outputs: 12/31/2004 - %V,%G,%Y = 53,2004,2004 print "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n"; // Outputs: 1/2/2005 - %V,%G,%Y = 53,2004,2005 print "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n"; // Outputs: 1/3/2005 - %V,%G,%Y = 1,2005,2005 print "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.setlocale.html" ><B CLASS="function" >setlocale()</B ></A > and <A HREF="function.mktime.html" ><B CLASS="function" >mktime()</B ></A > and the <A HREF="http://www.opengroup.org/onlinepubs/7908799/xsh/strftime.html" TARGET="_top" > Open Group specification of <B CLASS="function" >strftime()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.mktime.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.strtotime.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >mktime</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.datetime.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >strtotime</TD ></TR ></TABLE ></DIV ></BODY ></HTML >