Menu

PHP TUTORIALS - PHP Date & Time

PHP Date & Time

ADVERTISEMENTS

Getting the Time Stamp with time():


<?php
print time();
?>

ADVERTISEMENTS


948316201

ADVERTISEMENTS

Converting a Time Stamp with getdate():

KeyDescriptionExample
secondsSeconds past the minutes (0-59)20
minutesMinutes past the hour (0 - 59)29
hoursHours of the day (0 - 23)22
mdayDay of the month (1 - 31)11
wdayDay of the week (0 - 6)4
monMonth of the year (1 - 12)7
yearYear (4 digits)1997
ydayDay of year ( 0 - 365 )19
weekdayDay of the weekThursday
monthMonth of the yearJanuary
0Timestamp948370048

Example:


<?php
$date_array = getdate();
foreach ( $date_array as $key => $val )
{
   print "$key = $val<br />";
}
$formated_date  = "Today's date: ";
$formated_date .= $date_array[mday] . "/";
$formated_date .= $date_array[mon] . "/";
$formated_date .= $date_array[year];

print $formated_date;
?>


seconds = 27
minutes = 25
hours = 11
mday = 12
wday = 6
mon = 5
year = 2007
yday = 131
weekday = Saturday
month = May
0 = 1178994327
Today's date: 12/5/2007

Converting a Time Stamp with date():


date(format,timestamp)

FormatDescriptionExample
a'am' or 'pm' lowercasepm
A'AM' or 'PM' uppercasePM
dDay of month, a number with leading zeroes20
DDay of week (three letters)Thu
FMonth nameJanuary
hHour (12-hour format - leading zeroes)12
HHour (24-hour format - leading zeroes)22
gHour (12-hour format - no leading zeroes)12
GHour (24-hour format - no leading zeroes)22
iMinutes ( 0 - 59 )23
jDay of the month (no leading zeroes20
l (Lower 'L')Day of the weekThursday
LLeap year ('1' for yes, '0' for no)1
mMonth of year (number - leading zeroes)1
MMonth of year (three letters)Jan
rThe RFC 2822 formatted dateThu, 21 Dec 2000 16:01:07 +0200
nMonth of year (number - no leading zeroes)2
sSeconds of hour20
UTime stamp948372444
yYear (two digits)06
YYear (four digits)2006
zDay of year (0 - 365)206
ZOffset in seconds from GMT+5

Example:


<?php
print date("m/d/y G.i:s<br>", time());
print "Today is ";
print date("j of F Y, \a\\t g.i a", time());
?>


01/20/00 13.27:55
Today is 20 of January 2000, at 1.27 pm