Home >>PHP Date Time Functions >PHP date() Fuction

PHP date() Fuction

PHP date() Fuction

PHP date() function is used to format the local timestamp into a more readable date and time format and returns the formatted date string.

Syntax;

date(format, timestamp);

Parameter Values

Parameter Description
format This is a required parameter. This parameter defines the format of the outputted date string.
timestamp This is a n optional parameter. This parameter defines an integer Unix timestamp.

Here is an example of date() function in PHP;

<html>
<body>
<?php
echo date("d-m-Y")."<br>";
echo date("j-n-Y")."<br>";
echo date("d-M-Y")."<br>";
echo date("d-M-Y (D)")."<br>";
echo date("jS-M-Y (l)")."<br>";
?>
</body>
</html>

Output:
01-02-2020
1-2-2020
01-Feb-2020
01-Feb-2020 (Sat)
1st-Feb-2020 (Saturday)

Example 2:

<html>
<body>
<?php
echo date("d-m-Y",-706320000)."<br>";
echo date("j-n-y",-706320000)."<br>";
echo date("d-M-Y",-706320000)."<br>";
echo date("d-M-Y (D)",-706320000)."<br>";
echo date("jS-M-Y (l)",-706320000)."<br>";
echo date("jS-F-Y (l)",-706320000)."<br>";
?>
</body>
</html>

Output:
15-08-1947
15-8-47
15-Aug-1947
15-Aug-1947 (Fri)
15th-Aug-1947 (Friday)
15th-August-1947 (Friday)

No Sidebar ads