I need to calculate the timestamp of exactly 7 days ago using PHP, so if it\'s currently March 25th at 7:30pm, it would return the timestamp for March 18th at 7:30pm.
Sh
From PHP 5.2 you can use DateTime:
$timestring="2015-03-25";
$datetime=new DateTime($timestring);
$datetime->modify('-7 day');
echo $datetime->format("Y-m-d"); //2015-03-18
Instead of creating DateTime
with string, you can setTimestamp directly on object:
$timestamp=1427241600;//2015-03-25
$datetime=new DateTime();
$datetime->setTimestamp($timestamp);
$datetime->modify('-7 day');
echo $datetime->format("Y-m-d"); //2015-03-18