PHP Date

PHP Date function is used to format a local time/date.

The PHP Date() Function

Syntax :

date(string $format, timestamp) ;

The PHP date() function have 2 Parameter. Parameter format specifies the format of the timestamp. We can get second parameter timestamp using time() function.

Date Format :

The PHP date() function have three format for day, month and year as below.

d (Lowercase) - Specify the day of the month from 01 to 31.
m (Lowercase) - Specify a month from 01 to 12
y (Lowercase) - Specify a year in two digits
D (uppercase) - Specify the day of week from Sun to Sat.
M (uppercase) - Specify a month from Jan to Dec
Y (uppercase) - Specify a year in four digits
l (lowercase) - Specify the day from Sunday to Saturday.
F (uppercase) - Specify a month like April

Time Format :

We can show time in hour, minute and second format using below characters.

    H - Specify 24-hour format of an hour from 00 to 23
    h - Specify 12-hour format of an hour with leading zeros from 01 to 12
    i - Specify  Minutes with leading zeros from 00 to 59
    s - Specify Seconds with leading zeros from 00 to 59
    a - Lowercase  a specify Ante meridiem and Post meridiem such as am or pm
    A - Uppercase a specify Ante meridiem and Post meridiem such as AM or PM in uppercase.

Learn php date() function using below examples.

 

 

Example :

<?php
//code by aryatechno
echo "<br><b>Get date in different date format</b>";
echo "<br>Today Date in D, d M Y format is " . date("D, d M Y");
echo "<br>Today Date in d.m.Y format is " . date("d.m.Y");
echo "<br>Today Date in Y-m-d format is " . date("Y-m-d");
echo "<br>Today Date in d-F-Y format is " . date("d-F-Y");
echo "<br><b>Get date with time in different time format</b>";
echo "<br>Current Time in h:i:s a format is " . date("h:i:s a");
echo "<br>Current Date & Time in D, d M Y h:i:s A format is " . date("D, d M Y h:i:s A");


?>

Output :

Comments

Leave a Reply

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

77587