HOW DO I GET THE CURRENT DATE AND TIME IN PHP?

Get the current date, given a timezone in PHP?

This article will teach important and common problems related to PHP date and time functions. Learning these solutions will help speed up PHP programming and improve logic while working with date and time functions.

Date and time problems

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

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

date_default_timezone_set('Australia/Melbourne');

Or another example is LA – US:

date_default_timezone_set('America/Los_Angeles');

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

date_default_timezone_get();

So something like:

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

So the short answer to the question would be:

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

Then all the times would be to the timezone you just set.

Get the current date, given a timezone in PHP?
en English
X
Scroll to Top