Wednesday, March 12, 2008

Display date and time with PHP

Display date and time with PHP
Example:

$b = time ();
print date("g:i:s A D, F jS Y",$b);

Output: 02:10:10 PM Tue, March 12th 2008

PHP Date/Time Variables

If you're looking to customize your date/time display, here are the variables to use:

Days
d - day of the month 2 digits (01-31)
j - day of the month (1-31)
D - 3 letter day (Mon - Sun)
l - full name of day (Monday - Sunday)
N - 1 = Monday, 2 = Tuesday, etc. (1-7)
S - suffix for date (st, nd, rd)
w - 0 = Sunday, 1 = Monday (0-6)
z - day of the year (1 = 365)


Week
W - week of the year (1-52)


Month
F - Full name of month (January - December)
m - 2 digit month number (01-12)
n - month number (1-12)
M - 3 letter month (Jan - Dec)
t - Days in the month (28-31)


Year
L - leap year (0 no, 1 yes)
o - ISO-8601 year number (e.g. GMT, CST)
I - daylight savings (1 = yes, 0 = no)
O - offset GMT (e.g. 0200)
Z - offset in seconds (-43200 - 43200)
r - full RFC 2822 formatted date

No comments: