A group about Web Design & Development. Ask and Learn everything related to web design and development.

Post tutorial Report RSS PHP reference: date

Date functions listed with practical/technical examples.

Posted by on - Basic Server Side Coding

This one took a lot of time, and loads of space due to date formats part. Still, the reference format that can be found here:
(formatting in date() and gmdate() functions)

was sorted (and explained a bit more) according to the given type, e.g. Y/y: 1999/99 (the selected/current year).

The whole date functions reference (explanations, descriptions) is below:

As before, this is a little more practical/technical reference list.


//e.g. Africa: http://www.php.net/manual/en/timezones.africa.php

//parameters: latitude, longitude refer to latitude and longitude of the given localtion
//E.g. latitude: 10.0 for the Northern Hemisphere 
//latitude: -10.0 for the Southern Hemisphere
//longitude: 10.0 for the Eastern (EASTERN!) Hemisphere
//longitude: -10.0 for the Western Hemisphere
//positive values for the North and East
//negative values for the South and West

//Y/y: four/two digit represantation of a year (Y: 1999, y: 99)
//d/j: 01-31/1-31 numeric represantation of a day in month (d: 03, j: 3)
//S: -st, -nd, -rd, -th, suffix for the day in the month (31st, 22nd, 13th, etc.)
//D/l: shortened/full textual represantation of a day in week (D: Mon, l: Monday)
//M/F: shortened/full textual represantation of a month (M: Jan, F: January)
//N/w: numeric represantation of a day in week (N: 1 - Monday, 2 - Tuesday, etc. w: 0 - Monday, 1 - Tuesday, etc.)
//m/n: numeric represantations of a month (m: 01-12 (01, 02, ..., 12), n: 1-12)
//t: the TOTAL number of days in the given month
//L: a leap year? 1 yes, 0 no
//o: ISO-8601 year number (0000-9999)
//a/A lowercase/uppercase am/AM or pm/PM (a: am, pm, A: AM, PM)
//B swatch Internet time (000-999)
//g/h 12-hour format of an hour (g: 1 to 12, h: 01 to 12)
//G/H 24-hour format of an hour (G: 0 to 23, H: 00 to 23)
//i: minutes with leading zeroes (00-59)
//s: seconds with leading zeroes (00-59)
//use intvar() function to cut the leading zeroes:
//I: the date in Daylight Savings Time (1 true, 0 false)
//O: a difference to Greenwich time (GMT) in hours (e.g. +0200)
//T: timezone setting of the PHP machine, eg. MDT, CEST, etc.
//Z: returns 0
//c: ISO-8601 date (2010-12-12T20:20:59+00:00)
//r: RFC 2822 formatted date (Wed, 26 May 2010 18:00:00 +0300)
//U: seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
//format reference: 
//regular numeric formats: 
//Y, y, d, j, d, l, N, w, m, n, g, h, G, H, i, s
//regular textual formats:
//D, l, M, F
//irregular/different numeric formats:
//t, o, B, O
//irregular/different textual formats:
//S, a, A, T
//true/false formats:
//L, I, Z
//Unix formats:
//full/complete dates:
//c, r

//%a/%A shortened/full weekday name
//%b/%B shortened/full month name
//%c preferred date and time represantation (?)
//%C the two last digits of the year (00-99, e.g. 1999 would show 99)
//%d/%e the day of the month (%d: 01-31, %e: 1-31)
//%D = %m/%d/%y
//%g/%G the number of the week
//%h = %b
//%H 24-hour clock (00-23)
//%I 12-hour clock (01-12)
//%j day of the year (001-366, with leading zeroes)
//%m month (01-12)
//%M minute
//%n a newline ("<br />")
//%p am/pm
//%r time + am/pm
//%R time w/o am/pm (24-hour clock)
//%S seconds
//%t inserts a tab (_____ a long space before the actual start of a sentence/passage)
//%T = %H:%M:%S
//%u a weekday number (1-7), in Solaris operating system Sunday (not Monday) is 1
//%w a weekday number (0-6), Sunday is 0
//%U a week number of the current year (1-52/53 weeks) (the first Sunday is the first day of the first week)
//%V ISO 8601 week number of the current year (01-53), where the 1st week must have at least 4 days in the current year, and Monday is the first day of the first week
//%W a week number of the current year, the 1st Monday is the 1st day of the 1st week
//%x preferred date represantation without the time
//%X preferred time represantation without the date
//%Y/%y 1999/99 (a year w/ or w/o century)
//%Z/%z full/abbreviated timezone name
//%% a literal % character (%'s without additional % will be parsed)

//is_DST: is [during] Daylight Savings Time (is DST)?
//possible values:
//1 during Daylight Savings Time (DST)
//0 not during Daylight Savings Time (DST)
//-1 if it is unknown (the PHP will find out itself)
//this parameter is deprecated in PHP5!

//is_associative_array, returns an array with textual (associative) keys or numeric (default) keys, so, if
//false (default)
//keys will be: 0, 1, 2, 3, 4, 5, 6, 7, 8
//keys will be; tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday, tm_yday, tm_isdst

//return_float_type_variable: determines if the float variable (2.0005, 3.99, etc.) must be returned
//true: returns a float variable (2.99, 3.05)
//false (default: returns an integer (2, 3, 5, 9, etc.)

checkdate(12, 31, 2010); // checkdate(month, day, year)
date_default_timezone_get(); // date_default_timezone_get()
date_default_timezone_set("Europe/Paris"); // date_default_timezone_set(timezone)
date_sunrise(1137538800); date_sunrise(1137538800, SUNFUNCS_RET_STRING, 38.4, -9, 90, 1); // date_sunrise(timestamp, format, latitude, longitude, zenith, GMT_offset)
date_sunset(1137538800); date_sunset(1137538800, SUNFUNCS_RET_DOUBLE, 38.4, -9, 90, 1); // date_sunset(timestamp, format, latitude, longitude, zenith, GMT_offset)
date("m/d/Y"); date("m/d/Y", 1137538800); // date(date_format, timestamp)
getdate(); getdate(1137538800); // getdate(timestamp)
gettimeofday(); gettimeofday(true); // gettimeofday(return_float_type_variable)
gmdate("m/d/Y"); gmdate("m/d/Y", 1137538800); // gmdate(date_format, timestamp)
gmmktime(); gmmktime(23, 59, 59, 12, 31, 2010, 0); // gmmktime (hour, minute, second, month, day, year, is_DST)
gmstrftime("%D"); gmstrftime("%D", 1137538800); // gmstrftime(locale_date_format, timestamp)
idate("d"); idate("d", 1137538800); // idate(integer_date_format, timestamp)
localtime(); localtime(1137538800, true); // localtime(timestamp, is_associative_array)
microtime(); microtime(true); // microtime(return_float_type_variable)
mktime(); mktime(23, 59, 59, 12, 31, 2010, 0); // mktime(hour, minute, second, month, day, year, is_DST)
strftime("%D"); gmstrftime("%D", 1137538800); // strftime(locale_date_format, timestamp)
strptime("Dec 31 2010 23:59:59", "%D"); // strptime(date, locale_date_format)
strtotime("31 January 2009"); strtotime("31 January 2009", 1137538800); // strtotime(date, timestamp)
time(); // time()

//used in date_sunrise() and date_sunset() function

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Open to all members
Send Message
Join group
Group watch
Related Groups
Inside the Page
Inside the Page Hobbies & Interests with 57 members
Web devs & web game devs
Web devs & web game devs Hobbies & Interests with 43 members