Skip to content

How to Get Current Date & Time in PHP

How to Get Current Date Time with PHP with date() function or DateTime() class. A Sample example of Date and time in PHP with Timezone.

Category
PHP
Versions & support
About PHP →
On this page

Question – How to Get Current Date Time with PHP? How do I get current date and time in PHP script? PHP Script to get current date and time in Y-m-d H:i:s format?

You can use date() function to get current Date and Time in any PHP version. A DateTime PHP class is also available in PHP > 5.2 to get Date and Time. Also find the example to get date and time in JavaScript

PHP Date and Time

Print the current date and time using date() function. It will use the default timezone configured in php.ini.

Print the current date time using DateTime() class. It will also use the default timezone.

PHP Date and Time with Timezone:

You can also define the specific timezone for your Application. Now PHP will not use the system defined timezone.

Storing date and time UTC format is the best practice. UTC is refereed as Universal Time Coordinated. It is also known as “Z time” or “Zulu Time”.

Convert Date Time Timezone

For example, you have stored date (2018-01-11 01:17:23) in UTC timezone in your database. Now convert this DateTime to EST timezone.

After executing the above command, you will find the results like below.

2018-01-11 01:17:23

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top