Display Current Date and Time – PHP

Good Morning to all,
Some website used to display the current date or time in frond-end. This is very simple method to display the data or time using php.In PHP5, to display date and time provide inbuilt function for solve this problem.

The PHP date() function return the current date and time according to the built-in clock of the web server on which the script has been executed.

The PHP Date() Function

To display date in php page the date() helps to find this solution. The date() function in PHP convert a timestamp to a more readable time and date.



Parameter Description
format Required. Specifies the format of the timestamp.

d – Represents the day of the month (01 to 31).

m – Represents a month (01 to 12)

Y – Represents a year (in four digits)
timestamp Optional. Default is the current date and time

The format parameter in the date() function is required which specifies the format of returned date and time. However the timestamp is an optional parameter, if not included then current date and time will be used. The following statement displays today’s date:


The output will be:

Today is 2016/09/06

The PHP time() Function

To dispaly time in php page the time() helps to find the solution.

h – 12-hour format of an hour with leading zeros (01 to 12).

i – Minutes with leading zeros (00 to 59).

s – Seconds with leading zeros (00 to 59).

a – Lowercase Ante meridiem and Post meridiem (am or pm).


The output will be:

The time is 10:28:26am

Happy Coding

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *