PHP Date and Time


- Advertisement -

The PHP date() function is used to format a date and/or a time.


formatRequired. Specifies the format of the timestamp
timestampOptional. Specifies a timestamp. Default is the current date and time


Output: Today’s date is: 26-03-2020

Formatting options available in date() function:

The format parameter of the date() function is a string that can contain multiple characters allowing to generate dates in various formats.
Date-related formatting characters that are commonly used in the format string:

CharacterWhat It Means
dDay of the Month (Numeric 01 or 31)
DDay of the Week (String Mon to Sun)
lDay of the Week (String Mon to Sun)
FMonth (String Jan to Dec)
M Month (String Jan to Dec)
m Month (Numeric 01 to 12)
YYear in four-digit (Numeric 2008 or 2020 )
y Year in two-digit (Numeric 08 or 20 )
h Hour (in 12-hour format)
H Hour (in 24-hour format)
aAM or PM

Example of Date Format


Example of Time Format


PHP time() Function

The time() function is used to get the current time as a Unix timestamp. A UNIX timestamp for a particular time point represents the number of seconds that have elapsed between midnight on January 1970, and that time point. So, for example, the time point January 5 2008 10:15:00 AM in UNIX timestamp format would be 1199508300.

PHP can automatically turn a date value into a UNIX timestamp with mktime() function, which accepts day, month, year, hour, minute, and second arguments and returns a UNIX timestamp corresponding to that instant in time.

Below program explains usage of time() function in PHP:



March 26, 2020 04:32:56 PM

Other Important Tutorials on PHP Date and Time

- Advertisement -

Leave A Reply

Your email address will not be published.