Core PHP, PHP Beginners

PHP DATE | PHP Date Function

In this article, we talk about PHP Date functionality and all the operations which we used on web applications. Generally, we use...

Written by Bikash · 1 min read >

In this article, we talk about PHP Date functionality and all the operations which we used on web applications.

Generally, we use the PHP date() function for showing dates in a different format.

Some important points about Date PHP function,

  • Computer system store the date-time on UNIX timestamp format.
  • This measure the time on the second basis since beginning of epoch (midnight Greenwich Mean Time on January 1, 1970, i.e. January 1, 1970 00:00:00 GMT).
  • PHP Date function converts the timestamp time format to a human-readable format.
PHP date Function

PHP Date Syntax

date(format, timestamp);

PHP Date() function Syntax


PHP Date function date()

PHP date() returns date and time according to the builtin server or where you run that script.

How to Change PHP Date Format

Changing date format in PHP, PHP date function allowed some characters for changing the format like AM, PM and the day of the week. Some of the characters which is mainly used on the time of development are as follows,

  • Y – As a character suggest, refer to Year in four-digit like 2004 or 2020.
  • y – Small y also for a year but with last two-digit like 08 or 20.
  • M – Represent month as an acronym for Jan to Dec.
  • m – Represents numeric of the months like 01 to 12.
  • D – Represent the current day of the week, Mon to Sun.
  • d – Represents the day of the month with a numeric value like 01 to 31.

PHP Date format representation:



PHP time() Function

Same as the PHP date function, PHP time function is used to get the current time as UNIX timestamp value.

Output: 1581445636

Unix timestamp value

We can convert that UNIX timestamp value to human-readable value using PHP Date function. Check below,

Output: February 11, 2020 07:27:16

Change PHP time Format Representation

As PHP date, similarly PHP time() function has some character for formatting the time.

  • s – seconds with leading zeros, like 00 to 59
  • a – lowercase anti meridian and post meridian, like am or pm
  • h – an hour in 12-hour format with leading zeros, like 01 to 12.
  • H – an hour in 24-hour format with leading zeros, like 00 to 23
  • i – minutes with leading zeros, like 00 to 59
  • A – uppercase Anti meridian and Post meridian, like AM or PM


February 11, 2020 07:37:36 PM
07:37 pm

If you want you can use out PHP ONLINE EDITOR for checking those example source code execution.

How to Validate Date String in PHP

Want to know more check PHP official website

Happy Coding..!

Was this article helpful?
Written by Bikash
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP. Profile

One Reply to “PHP DATE | PHP Date Function”

Leave a Reply

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