Date and Time

time();

 

Works on the number of seconds since the UNIX epoch 1 January 1970 00:00:00 GMT

 

<?php
	//display the current number of seconds since Epoch
	echo time() ;
?>

 

date();

 

  • converts a timestamp to a more human readable form.
  • requires a format parameter.
  • optional timestamp - defaults to current date/time.
<?php
	$now = time() ;

	echo date("Y m d") . "<br><br>" ;
	echo date("YmdHis") . "<br><br>" ;
	echo date("Ymd-H:i:s") . "<br><br>" ;
	echo date("dS F Y") ;
?>

 

Format paramaters (case sensitive!):

a Lowercase am/pm am or pm
A Uppercase am/pm AM or PM
B Swatch Internet Time 000 to 999
c ISO 8601 date, time, and time zone 2012-11-26T14:26:55+01:00
d 2-digit day of month, leading zeros 01 to 31
D Day string, three letters Mon, Thu, Sat
F Month string, full January, April
g 12-hour clock hour, no leading zeros 1 to 12
G 24-hour clock hour, no leading zeros 0 to 23
h 12-hour clock hour, leading zeros 01 to 12
H 24-hour clock hour, leading zeros 00 to 23
i Minutes with leading zeros 00 to 59
I Is daylight savings time active? 1 if yes, 0 if no
j Day of month, no leading zeros 1 to 31
l Day string, full Sunday, Tuesday
L Is it a leap year? 1 if yes, 0 if no
m Numeric month, leading zeros 01 to 12
M Short month string Jan, Mar
n Numeric month, no leading zeros 1 to 12
O Difference from GMT 100
r RFC-822 formatted date Sun, 17 May 2007 21:30 +0000
s Seconds, with leading zeros 00 to 59
S English ordinal suffix for day number st, nd, rd, or th
t Number of days in month 28 to 31
T Time zone for server GMT, CET, EST
U Unix Timestamp 1353936090
w Numeric day of week 0 (Sunday), 6 (Saturday)
W ISO-8601 week number of year 30 (30th week of the year)
y Two-digit representation of year 75, 12
Y Four-digit representation of year 1975, 2012
z Day of year 0 to 366
Z Time zone offset in seconds -43200 to 43200

 

 

mktime();

 

Returns the UNIX timestamp for the specified date.

 

mktime(hour, minute, second, month, day, year, is_dst) ;

 

<?php
	echo $unixtime = mktime(13, 40, 33, 11, 26, 2012, -1) . "<br>";
?>

 

Useful for calculations involving date/time.

 

Use leading zeroes for values less than 10.

 

All parameters optional.

 

Order must be separated with comma ,

Leave a Reply