Php – How to get the current date and time in PHP


Which PHP function can return the current date/time?

Best Solution

The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions are called to.

I'm in Melbourne, Australia so I have something like this:


Or another example is LA - US:


You can also see what timezone the server is currently in via:


So something like:

$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;

So the short answer for your question would be:

// Change the line below to your timezone!
$date = date('m/d/Y h:i:s a', time());

Then all the times would be to the timezone you just set :)