PHP gmdate() Function

What is a gmdate Function?
How to format GMT/UTC date and time?


The "gmdate()" is used to format a GMT/UTC date and time.



In the above syntax the "format" is to specify how to return the results, 35 pre-defined formats are available. The "timestamp" is an optional field.

Example :

echo("Result with date():<br />");
echo(date("l") . "<br />");
echo(date("l dS of F Y h:i:s A") . "<br />");
echo("Oct 3,1975 was on a ".
date("l", mktime(0,0,0,10,3,1975))."<br />");
echo(date(DATE_RFC822) . "<br />");
echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "<br /><br />");
echo("Result with gmdate():<br />");
echo(gmdate("l")."<br />");
echo(gmdate("l dS of F Y h:i:s A")."<br />");
echo("Oct 3,1975 was on a ".
gmdate("l", mktime(0,0,0,10,3,1975))."<br />");
echo(gmdate(DATE_RFC822)."<br />");
echo(gmdate(DATE_ATOM,mktime(0,0,0,10,3,1975))."<br />");
Result :

Result with date():
Tuesday 24th of January 2006 02:41:22 PM
Oct 3,1975 was on a Friday
Tue, 24 Jan 2006 14:41:22 CET
Result with gmdate():
Tuesday 24th of January 2006 01:41:22 PM
Oct 3,1975 was on a Thursday
Tue, 24 Jan 2006 13:41:22 GMT

In the above example, the date() return the value of the current timezone, whereas, gmdate() function returns the value for GMT timezone values.

Note :

(PHP 4, PHP 5)

PHP Topics

Ask Questions

Ask Question