Getting the Current Date and Time In PHP

Computers include Web servers, as well as your own PC and keep track of the current date and time using a built-in clock. You can access this clock’s value with the PHP time() function, which simply returns the current date and time as a timestamp:

echo time(); // Displays e.g. “1229509316”

You can use time() in combination with other PHP functions to display the current time and compare dates and times against the current date and time, among other things.

When using any of PHP’s date – related functions, you get an error message telling you that it is not safe to rely on the system’s time zone settings, you need to configure PHP’s time zone.

Scroll to Top