How to Get the Current Date and Time in PHP

How to get current time in Datetime format PHP?

You should find info about the DateTime class to work with dates in php

$d = new DateTime('now');
$d->setTimezone(new DateTimeZone('UTC'));
echo $d->format('Y-m-d H:i:s');

How to get current date and time in php

Try this.

date_default_timezone_set('Asia/Kolkata'); 
echo date("Y-m-d H:i:s"); // time in India

Preset current date and time in input type datetime using php

Well.. You can just set the value by using the "value" attribute:

<input type="datetime-local" name="followupon" value="2014-01-02T11:42:13.510">

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#Value for more information

If you want to use the current date, you can use php like so:

<input type="datetime-local" name="followupon" value=<?php echo date('Y-m-d\TH:i:s'); ?>">

PHP Add one hour to current date time

$my_date_time = date("Y-m-d H:i:s", strtotime("+1 hours"))

How to get current date in certain format with PHP?

Please try following code :

echo "current time: " .date('Y-m-d h:i:s');

echo "<br>current timestamp minus 15 minutes :". date('Y-m-d H:i:s', strtotime('-15 minutes'));

Now' Function query in php to get current date and time

No Need to execute query if you want to get current date and time in PHP. Check below date function

<?php echo date('d-M-Y H:i:s'); ?>

Get the current date and time in PHP with '2016-07-04 00:00:00.000' format

Use date->format http://php.net/manual/it/function.date.php

$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s.u');


Related Topics



Leave a reply



Submit