Home >>PHP Date Time Functions >PHP gmdate() Function

PHP gmdate() Function

PHP gmdate() Function

PHP gmdate() function is used to format a GMT/UTC date and time and return the formatted date strings. It is similar to the date() function but the only difference is it returns the time in Greenwich Mean Time (GMT). It accepts two parameters $format and $timestamp. It returns a formatted date string as output on success and FALSE or E_WARNING on failure.

Syntax:

 gmdate(format, timestamp);

Parameter Values

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

Here is an example of gmdate() function in PHP:

<html>
<body>
<?php
echo gmdate("d-m-Y")."<br>";
echo gmdate("d-M-Y")."<br>";
echo gmdate("l")."<br>";
echo gmdate("jS F,Y")."<br>";
echo gmdate("jS M, Y (l)")."<br>";
?>
</body>
</html>
Output:
01-02-2020
01-Feb-2020
Saturday
1st February,2020
1st Feb, 2020 (Saturday)

Example 2:

<html>
<body>
<?php
echo gmdate("d-m-Y",1581638400)."<br>";
echo gmdate("d-M-Y",1581638400)."<br>";
echo gmdate("l",1581638400)."<br>";
echo gmdate("jS F,Y",1581638400)."<br>";
echo gmdate("jS M, Y (l)",1581638400)."<br>";
?>
</body>
</html>
Output:
14-02-2020
14-Feb-2020
Friday
14th February,2020
14th Feb, 2020 (Friday)

No Sidebar ads