Good day everyone. Today I’m gonna teach you on using the date function in PHP.
This tutorial is all about Using date function in PHP.
PHP date() function takes two parameters, and one is the format string. And today we will just learn about it.
Sometimes, web developers didn’t specify a timestamp so date() will be default to the current date and time. It returns a formatted string representing the appropriate date.
A typical call to the date function could be
This call produces a date in the format 7th May 2017. The format codes accepted by date will be listed below:
a – morning or afternoon, represented as two lowercase characters, either am or pm.
A – morning or afternoon, represented as two uppercase characters, either AMor PM.
B – swatch internet time universal time scheme. More information is available at http://www.swatch.com/
c – ISO 8601 date. A date is represented as YYYY-MM-DD. An uppercase T separates the date from the time. The time is represented as HH:MM:SS.
d – day of the month as two-digit number with leading zero
D – day of the week in three-character abbreviated text format.
e – timezone identifier
F – month of the year in full text format
g – hour of the day in 12-hour format without leading zeros.
G – hour of the day in 24-hour format without leading zeros.
h – hour of the day in 12-hour format with leading zeros.
H – hour of the day in 24-hour format with leading zeros.
i – minutes past the hour with leading zeros
I – daylight savings time, represented as a Boolean value.
j – day of the month as a number without leading zeros
l – day of the week in full-text format
L – leap year, represented as a Boolean value.
m – month of the year as a two-digit number with leading zeros
M – month of the year in three-character abbreviated text format
n – month of the year as a number without leading zeros
o – ISO-8601 year number. This has the same value as Y, accept that if the ISO week number (W) belongs to the previous or next year, the year is used instead
O – difference between the current time zone and GMT in hours
r – RFC822-formatted date and time – for example, +1600.
s – second past the minute with leading zeros. The range is from 00 to 59
S – ordinal suffix for dates in two-character format. It can be st, nd, rd, or th, depending on the number it follows
t – total number of days in the date’s month
T – time zone settings of the server in three-character format
U – total number of seconds form January 1, 1970, to this time; also known as Unix timestamp for this date.
w – day of the week as a single digit. The range is form 0 (Sunday) to 6 (Saturday)
W – week number in the year; ISO-8601 compliant.
y – year in two digit format – for example, 17.
Y – year in four-digit format – for example, 2017.
z – days of the year as a number. The range is 0 to 365
Z – offset for the current time zone in seconds. The range is -43200 to 43200.
If you have questions regarding this tutorial entitled as “Using date() function in PHP” feel free to ask us by commenting below or visit on our contact page. Thank you.