Display the Current Date

If you want to display the current date, you can use the following code:


$current_timestamp = date('m/d/Y h:i:s a', time());

echo $current_timestamp;


The following will output something like:

07/30/2022 03:47:56 pm

By calling the time function with time(), you get the number of seconds since Unix Epoch (January 1 1970 00:00:00 GMT).

The date function formats the time, converting the seconds into the month, day, year, hour, minute, and second. You can control the display by changing the characters that represent what you want it to show.

Format CharacterDescriptionExample Returned Values
mNumeric representation of a month, with leading zeros01 through 12
dDay of the month, 2 digits with leading zeros01 to 31
YA full numeric representation of a year, at least 4 digits, with - for years BCE.Examples: -005507871999200310191
h12-hour format of an hour with leading zeros01 through 12
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59
aLowercase Ante meridiem and Post meridiemam or pm

For a full list, you can refer to the PHP documentation, which can be found here.