www.pickatutorial.com Computer Tutorials
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons PHP Date and Time Functions Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
The basic PHP date and time functions let us easily format timestamps for use in our database queries and calendar functions. They also allow us simply print the date on screen or on a report etc.

date()
The date() function returns the current server timestamp. It is formatted according to a set of parameters. The syntax of data() is as under:

date(format, [timestamp]);

If the timestamp parameter is not provided, the current timestamp is assumed. Following table shows the available formats.

date() Function Formats
Character Description
a Prints “am” or “pm”
A Prints “AM” or “PM”
h Hour in 12-hour format (01 to 12)
H Hour in 24-hour format (00 to 23)
g Hour in 12-hour format without a leading zero (1 to 12)
G Hour in 24-hour format without a leading zero (0 to 23)
i Minutes (00 to 59)
s Seconds (00 to 59)
Z Time zone offset in seconds (–43200 to 43200)
U Seconds since the Epoch (January 1, 1970 00:00:00 GMT)
d Day of the month in two digits (01 to 31)
j Day of the month in two digits without a leading zero (1 to 31)
D Day of the week in text (Mon to Sun)
l Day of the week in long text (Monday to Sunday)
w Day of the week in numeric, Sunday to Saturday (0 to 6)
F Month in long text (January to December)
m Month in two digits (01 to 12)
n Month in two digits without a leading zero (1 to 12)
M Month in three-letter text (Jan to Dec)
Y Year in four digits (2000)
y Year in two digits (00)
z Day of the year (0 to 365)
t Number of days in the given month (28 to 31)
S English ordinal suffix (th, nd, st)
checkdate()
The checkdate() function is used to validates a given date. Successful validation means that the year is between 0 and 32767, the month is between 1 and 12, and the proper number of days is in each month (leap years are accounted for, as well).

The syntax of checkdate() follows:
checkdate(month, day, year);

mktime()
The mktime() function returns the UNIX timestamp as a long integer (in the format of seconds since the Epoch, or January 1, 1970) for a given date. The primary use of mktime() is to format dates in preparation for mathematical functions and date validation.

The syntax of mktime() follows:
mktime(hour, minute, second, month, day, year);

time() and microtime()
The time() function returns the current system time, measured in seconds since the Epoch.

The syntax of time() function follows:

time();

The result of the above could be such as 958954466.

Calling microtime() function adds a count of microseconds, so instead of just receiving a result like above, we could get a result like 0.93121634 958954466, at the exact moment we asked for the time since the Epoch (includes both seconds and microseconds).


Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.