Home >>Advance PHP Tutorial >PHP Date and Time Function

PHP Date and Time Function

PHP Date & Time Function with Example

PHP Supports many other date/time manipulation functions, which allow you to check if a date is valid or convert between time zones.

PHP Date/Time Common Functions
Functions What it Does
checkdate() Checks a date for Validity
strtotime() Creates Timestamps from English-language Descriptions
gmdate() Expresses a timestamp in GMT
date_diff() It will Returns Difference between two dates
date( ) Formats a local date and time
getdate() Returns date/time information of a timestamp or the current local date/time
mktime() Returns the Unix timestamp for a date
time() Returns the current time as a Unix timestamp

PHP Date/Time parameters

Character What It Means
d Day of the Month(Numeric)
D Day of the Week(String)
l Day of the Week(String)
F Month(String)
M Month(String)
m Month(Numeric)
Y Year
h Hour(in 12-hour format)
H Hour(in 24-hour format)
a AM or PM
i Minute
s Second

Use Of date( ) Function

Through date( ) function we can display a local date and time.

This function accpets two arguments a formating string and a timestamp

The formatting string is a sequence of characters, each of which has a special meaning


echo "It is now ".date("h:i a d M Y",mktime(12,28,13,10,11,2019));
Output : It is now 12:28 pm 11 October 2019

Popular Tutorials