DATE AND TIME FUNCTIONS Manju Dhankhar 060341048
getdate([int timestamp]) Returns an associative array containing the timestamp. echo(getdate()); • • • • • • • • •
Array ( [seconds] => 45 [minutes] => 52 [hours] => 14 [mday] => 24 [wday] => 2 [mon] => 1 [year] => 2006 [weekday] => Tuesday [month] => January)
Checkdate(month,day,year) • Returns true if the specified date is valid, and false otherwise. • A date is valid if: – month is between 1 and 12 inclusive – day is within the allowed number of days for the particular month – year is between 1 and 32767 inclusive • • The output of the code above will be: • True and False
date(string format,[int timestamp]) • • • •
• • • • • • • •
d - The day of the month (from 01 to 31) D - A textual representation of a day (three letters) j - The day of month without leading zeros (1 to 31) S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th.) w - A numeric representation of the day (0 for Sunday through 6 for Saturday) z - The day of the year (from 0 through 365) a - Lowercase am or pm A - Uppercase AM or PM g - 12-hour format of an hour (1 to 12) G - 24-hour format of an hour (0 to 23) h - 12-hour format of an hour (01 to 12) H - 24-hour format of an hour (00 to 23)
• F - A full textual representation of month(January December) • m - A numeric representation of a month (from 01 to 12) • M - A short textual representation of a month (three letters) • n - A numeric representation of a month, without leading zeros (1 to 12) • t - The number of days in the given month • L - Whether it's a leap year (1 if it is a leap year, or else 0) • Y - A four digit representation of a year • y - A two digit representation of a year • i - Minutes with leading zeros (00 to 59) • s - Seconds, with leading zeros (00 to 59) • O - Difference to Greenwich time (GMT) in hours(eg +0100)
• echo date(“l”) Thursday • echo date(“l dS F Y h :i:s A”) Wednesday 15th January 2006 05:51:35 AM • echo date(“l \t\h\e jS”); Wednesday the 15th • echo date(“F j , Y , g:I a”); August 16 , 2006 , 5:15 pm • echo date(“ H:m:s \m \I\s \m\o\n\t\h”); 17:03:17 pm is month • echo date(“ H : I : s”); 17:16:19
gmdate(string format,[int timestamp]) • Identical to date() function except that the time returned is Greenwich Mean Time. • echo(date("l") Tuesday • echo(date("l dS \of F Y h:i:s A") Tuesday 24th of January 2006 02:41:22 PM
gmmktime(int hour,int minute,int second, int month,int day,int year,int is_dst) The gmmktime() function returns a Unix timestamp for a GMT date. • is_dst: 1 if the time is during daylight savings time (DST) 0 if it is not -1 (the default) if it is unknown •
Localtime([int timestamp], [boolean is_associative]) • Returns an array that contains the time components of a Unix timestamp echo (localtime()); Array ( [0] => 28 [1] => 35 [2] => 13 [3] => 25 [4] => 0 [5] => 106 [6] => 3 [7] => 24 [8] => 0 )
echo(localtime(time(),tru e)); Array ( [tm_sec] => 28 [tm_min] => 35 [tm_hour] => 13 [tm_mday] => 25 [tm_mon] => 0 [tm_year] => 106 [tm_wday] => 3
Is_associative: Specifies whether to return an associative or indexed array. If false - indexed array if true - associative array. • The keys of the associative array are: – [tm_sec] - seconds – [tm_min] - minutes – [tm_hour] - hour – [tm_mday] - day of the month – [tm_mon] - month of the year (January=0) – [tm_year] - Years since 1900 – [tm_wday] - Day of the week (Sunday=0) – [tm_yday] - Day of the year – [tm_isdst] - Is daylight savings time in effect
microtime(get_as_float) • The microtime() function returns the current Unix timestamp with microseconds. • It is available with only those operating systems that support the gettimeofday(). Output would be: 0.25139300 1138197510
strtotime(time,now) • The strtotime() function parses an English textual date or time into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Output would be as follows: 1139219304 1139503709 1139180400 1138489200
time(void) • The time() function returns the current time as a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). The output of the code above could be: 1138618081 Mon January 30 2006
»THANK YOU