I have the following code:
$now = date(\"Y-m-d H:m:s\");
$date = date(\"Y-m-d H:m:s\", strtotime(\'-24 hours\', $now));
However, now it
You can simply use time()
to get the current timestamp.
$date = date("Y-m-d H:m:s", strtotime('-24 hours', time()));
This may be helpful for you:
//calculate like this
$date = date("Y-m-d H:m:s", (time()-(60*60*24)));
//check the date
echo $date;
$now = date("Y-m-d H:i:s");
$date = date("Y-m-d H:i:s", strtotime('-24 hours', strtotime($now)));
Add "strtotime" before $now, and Y-m-d H:m:s replace with Y-m-d H:i:s
this should work, too
$date = date("Y-m-d H:m:s", strtotime('-24 hours'));
you can do this in many ways...
echo date('Y-m-d H:i:s',strtotime('-24 hours')); // "i" for minutes with leading zeros
OR
echo date('Y-m-d H:i:s',strtotime('last day')); // 24 hours (1 day)
Output
2013-07-17 10:07:29
Simplest way to sub or add time,
<?php
**#Subtract 24 hours**
$dtSub = new DateTime('- 24 hours');
var_dump($dtSub->format('Y-m-d H:m:s'));
**#Add 24 hours**
$dtAdd = new DateTime('24 hours');
var_dump($dtAdd->format('Y-m-d H:m:s'));die;
?>