Fri, 17 May 2024


How to display the date in an appropriate format using PHP?

By: Anton, NetArt Media
Fri, 16 July 2021

You should use the special date function in PHP.

Take a look at the example
<?php
echo date("D M d");
?>

will display: Mon Feb 03

where

Y = Year eg. 2003
y = Year eg. 03
M = Month eg. Jan
m = Month eg. 01
D = Day eg. Fri
d = Day eg. 03
z = Day of the year eg. 002
H = Hours in 24 hour format eg. 07
h = Hours in 12 hour format eg. 7
i = Minutes eg. 29
s = Seconds eg. 28
U = Seconds since epoch eg. 1041604168


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox