The Date function is use to optimize the dates in proper and human readable formats.
The dates can be used for many purpose as the articles published date , articles last updated in database .
<?php date('format', [timestamp]); ?>
date() : is a function that returns the current time on on server .
format : indicates which format of date to want to display , as for example “Y-m-d” , “F j Y” etc
timestamps : is a optional , if on timestamps is provided it takes the server default time stamps.
<?php echo date('Y'); ?>
For the month and year the following characters can be used to format the day,month,year :
- d – Day Representation of the month; two digits with leading zeros (01 or 31)
- D – Day Representation day of the week in text as an abbreviation (Mon to Sun)
- m – Month Representation in numbers with leading zeros (01 or 12)
- M – Month Representation month in text, abbreviated (Jan to Dec)
- y – Year Representation in two digits (08 or 14)
- Y – Year Representation year in four digits (2008 or 2014)
For Example :
echo date("d/m/Y") . "<br>";
echo date("d-m-Y") . "<br>";
In the same way you can use the following characters to format the time string:
- h – Hour Representation in 12-hour format with leading zeros (01 to 12)
- H – Hour Representation in 24-hour format with leading zeros (00 to 23)
- i – Minutes Representation with leading zeros (00 to 59)
- s – Seconds Representation with leading zeros (00 to 59)
- a – Lowercase Representation for ante meridiem and post meridiem (am or pm)
- A – Uppercase Representation for Ante meridiem and Post meridiem (AM or PM)
For Example :
echo date("h:i:s") . "<br>";
echo date("F d, Y h:i:s A") . "<br>";
echo date("h:i a");
July 14, 2018 04:17:14 AM