PHP Most used Date format Example

PHP Most used Date format Example

Some of the important PHP date formats are given below with examples,

1. Printing time and day [12 hour format]:

<?php echo date('g:i, jS F'); ?>


[plain gutter=”false”]3:51, 17th March[/plain]

2. Printing time and day [24 hour format]:

<?php echo date('H:i, jS F'); ?>


[plain gutter=”false”]15:52, 17th March[/plain]

3. Printing month:date:year

<?php echo date('m.d.y'); ?>


[plain gutter=”false”]03.17.14[/plain]

4. Printing time with am/pm

<?php echo date('g:i a'); ?>


[plain gutter=”false”]3:55 pm[/plain]

5. Printing time(am/pm) with month, date and year

<?php echo date('g:i a, m:d:Y'); ?>


[plain gutter=”false”]4:05 pm, 03:17:2014[/plain]

1. y prints year in 2 digit format (eg: 2014 will be printed as 14 only).
2. Y prints year in 4 digit format (eg: 2014).

If you want to print in any other format, let us know in the comment area.

PHP Recommended Books:

703 total views, 3 views today

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.