• Register

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:
W3schools.com
W3schools.com
(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:
W3schools.com

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

<?php

//timezone:
//http://www.php.net/manual/en/timezones.php
//e.g. Africa: http://www.php.net/manual/en/timezones.africa.php
//date_default_timezone_set("Africa/Cairo");
//date_default_timezone_set("Africa/Lagos");
//etc.

//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

//date_format:
//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:
//intvar(date("i"));
//intvar(date("s"));
//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:
//U
//full/complete dates:
//c, r

//locale_date_format:
//%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
//true
//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()

//format: SUNFUNCS_RET_STRING, SUNFUNCS_RET_DOUBLE, SUNFUNCS_RET_TIMESTAMP
//used in date_sunrise() and date_sunset() function

?>
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: