How to Get the Current Date and Time in PHP

How to Get the Current Date and Time in PHP

In this post we will give you information about How to Get the Current Date and Time in PHP. Hear we will give you detail about How to Get the Current Date and Time in PHPAnd how to use it also give you demo for it if it is necessary.

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;
?>

 

Hope this code and post will helped you for implement How to Get the Current Date and Time in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US