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 gutter=”0″]
<?php echo date(‘g:i, jS F’); ?>
[/php]

Output:

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

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

[php gutter=”0″]
<?php echo date(‘H:i, jS F’); ?>
[/php]

Output:

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

3. Printing month:date:year

[php gutter=”0″]
<?php echo date(‘m.d.y’); ?>
[/php]

Output:

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

4. Printing time with am/pm

[php gutter=”0″]
<?php echo date(‘g:i a’); ?>
[/php]

Output:

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

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

[php gutter=”0″]
<?php echo date(‘g:i a, m:d:Y’); ?>
[/php]

Output:

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

Note:
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:

Leave a Reply