Date and time format in PHP with example

By | December 11, 2013

Today, In this article i will explain date various format in PHP and how to use it in Php according to our requirement in Programming functionality.

In Php, date() function accepts two parameters. That are Format string and time as integer.

datetime

Let’s play with Date() function by examples.

Date formatting :

Below are list of Date format characters:

d – Numeric representation of a day, with leading zeros 01 through 31.
m – Numeric representation of a month, with leading zeros 01 through 12.
y – Numeric representation of a year, two digits.

D – Textual representation of a day, three letters Mon through Sun.
j – Numeric representation of a day, without leading zeros 1 through 31.
n – Numeric representation of a month, without leading zeros 1 through 12.
Y – Numeric representation of a year, four digits.

S – English ordinal suffix for the day of the month. Consist of 2 characters like st, nd, rd or th.
F – Textual representation of a month, January through December.

M – Textual representation of a month, three letters Jan through Dec.

l – textual representation of the day of the week Sunday through Saturday.

Time formatting :

Below are list of Time format characters:

G – 24-hour format of an hour without leading zeros 0 through 23.
i – Numeric representation of minutes with leading zeros 00 through 59.
s – Numeric representation of seconds with leading zeros 00 through 59.
H – 24-hour format of an hour with leading zeros 00 through 23.
a – Lowercase Ante meridiem and Post meridiem am or pm.
g – 12-hour format of an hour without leading zeros 1 through 12.
A – Uppercase Ante meridiem and Post meridiem AM or PM.
h – 12-hour format of an hour with leading zeros 01 through 12.

Example of combine both date and time format.

Category: Php

Leave a Reply

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