Date Quick Reference

Any tutorials (or useful resources) should go in here.
Post Reply
nyo
Posts: 124
Joined: Mon May 09, 2011 1:55 pm
Location: Mobile

Date Quick Reference

Post by nyo »

Here is my date & time reference file. No need to search internet or check php.net every time I want to display date or time in a different format. I am sure this could be helpful to other newbies like me. Because I have spent some hours for figuring out how date() function works.

[syntax=php]<?php

date_default_timezone_set('UTC'); //Available since PHP 5.1

//Display year only: 2011
echo date('Y');

//Display month and day only: May, 15
echo date('F, j');

//Display full date: Sunday, May 15th 2011
echo date('l, F dS Y');

//Display date with dots: 15.05.2011
echo date('d.m.Y');

//Display time in hours and minutes 11:38
echo date('H:i');

//Display date and time 15.05.2011, 11:38
echo date('d.m.Y, H:i');

//Display nth day of the month 15th of May
echo date('jS \o\f F');

//Display time with am/pm May 15, 2011, 11:38 am
echo date('F j, Y, g:i a');

//Display time EST, PST, etc. Sun May 15 11:38:58 UTC 2011
echo date("D M j G:i:s T Y");

//Text in date function It is the 15th day of the month.
echo date('\I\t \i\s \t\h\e jS \d\a\y \o\f \t\h\e \m\o\n\t\h.');

/*
Reference: http://tr.php.net/manual/en/function.date.php

DAY

d = Day eg. 03 | 01 - 31
j = Day eg. 14 | 1 - 31
D = Day eg. Fri
l = Day eg. Saturday
N = Day eg. 3 | 1 - 7 (added in PHP 5.1.0)
S = Day suffix eg. st, nd, rd, th | works well with j
z = Day of the year | 0 - 365

WEEK

W = Week of the year | 1-52 (added in PHP 4.1.0)

MONTH

F = Full Text Month eg. January
m = Month eg. 01 | 01 - 12
n = Month eg. 1 | 1 - 12
M = Month eg. Jan
t = Number of days in the given month | 28 - 31

YEAR

L = 1 if it is a leap year, 0 otherwise
o = ISO-8601 year number. Same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0) Examples: 1999 or 2003
Y = Year eg. 2011
y = Year eg. 11

TIME

a = Lowercase 12hr time syntax eg. pm
A = Uppercase 12hr time syntax eg. PM
B = Swatch Internet time | 000 - 999
g = Hours in 12 hour format eg. 7 | 1 - 12
h = Hours in 12 hour format eg. 07 | 01 - 12
G = Hours in 24 hour format eg. 16 | 0 - 23
H = Hours in 24 hour format eg. 17 | 00 - 23
i = Minutes eg. 29 | 00 - 59
s = Seconds eg. 28 | 00 - 59
u = Microseconds eg. 654321 (added in PHP 5.2.2)
U = Seconds since the UNIX epoch eg. 1241604168
O = GMT time difference in hours eg. +0400
T = Timezone setting eg. GMT, PST, EST, etc

TIMEZONE

e = Timezone identifier, eg. UTC, GMT, Atlantic/Azores (added in PHP 5.1.0)
I = Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise.
O = Difference to Greenwich time (GMT) in hours eg. +0200
P = Difference to Greenwich time (GMT) with colon between hours and minutes, eg. +02:00 (added in PHP 5.1.3)
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

FULL DATE/TIME

c = ISO 8601 date eg. 2004-02-12T15:19:21+00:00 (added in PHP 5)
r = RFC 2822 formatted date eg. Thu, 21 Dec 2000 16:01:07 +0200
*/

?>[/syntax]
Last edited by nyo on Mon May 16, 2011 4:38 am, edited 1 time in total.
libeco
Posts: 104
Joined: Sat May 07, 2011 9:56 am

Re: Date Quick Reference

Post by libeco »

That's actually not such a bad idea. Just to have some regularly used date strings nearby. I might copy your idea and keep some strings as texts to re-use when I need.
Post Reply