Q:

How to Get the Current Date and Time in PHP

0

How to Get the Current Date and Time in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP date() Function

You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s')date('d/m/y H:i:s'), and so on.

Try out the following example to see how it basically works:

<?php
// Return current date from the remote server
$date = date('d-m-y h:i:s');
echo $date;
?>

The date and time returned by the above example is based on the server's default timezone setting. If you want to show date and time as per user's timezone, you can set the timezone manually using the date_default_timezone_set() function before the date() function call.

The following example shows the date and time in India timezone which is Asia/Kolkata.

<?php
// Set the new timezone
date_default_timezone_set('Asia/Kolkata');
$date = date('d-m-y h:i:s');
echo $date;
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Make a Redirect in PHP... >>
<< How to Check If a String Contains a Specific Word ...