saftutorials.com
PHP DATE & TIME

The PHP date() function is a pre-built function which is used to get current date and time. You can display current date and time using this function. By this tutorials, you can learn PHP Date, Time all function and work.


Syntax of PHP date() function

date(format, timestamp)


These are date parameters and its description

format (This parameter is required and identify clearly format of timestamp)

timestamp (This is an optional parameter and identify clearly timestamp, Default is current date and time)


Some example of print current date in different formats

<!DOCTYPE html>
<html>
<body>
<?php
echo "Today is " . date("l") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y-m-d");
?>
</body>
</html>

This program will output this result:

Today is (Dayname here)

Today is 2017.07.30

Today is 2017/07/30

Today is 2017-07-30

d - Represents the day of the month (01 to 31)

m - Represents a month (01 to 12)

Y - Represents a year (in four digits)

l - Represents the day of the week


Example of print current time

<!DOCTYPE html>
<html>
<body>
<?php
echo "The time is " . date("h:i:s a");
?>
</body>
</html>

This program will output this result: 

The time is 04:49:15 pm


h - Represents 12-hour format of an hour of the day (01 to 12)

i - Represents Minutes of the day (00 to 59)

s - Represents Seconds of the day (00 to 59)

a - Represents am or pm


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic