Menu

Add Topic

programming

waiting answer July 28, 2021

How to Get the Current Date and Time in PHP

Answers
June 10, 2021

You can use the PHP date() function to get the current date and time in various formats.

     <?php
        $date = date('Y-m-d H:i:s a');
        echo $date;
     ?>

Sample Output

            2021-06-08 14:06:10 pm

The date and time returned above based on the server's default timezone that set in the server.

In PHP, You can set the default timezone using date_default_timezone_set() function.

The below program shows the date and time in India. Which is Asia/Kolkata

     <?php
        date_default_timezone_set('Asia/Kolkata');
        $date = date('Y-m-d H:i:s a');
        echo $date;
     ?>

Sample Output

          2021-06-08 11:42:07 am

0 0

Please Login to Post the answer

Leave an Answer