dc_jt Posted March 30, 2007 Share Posted March 30, 2007 Im looking to get the date 7 days ago. I know how to do 7 days ahead: $timeStamp = strtotime($oLastBatchDate->Last); $timeStamp += 24 * 60 * 60 * 7; $NextBatchDate = date("Y-m-d H:i:s", $timeStamp); However, does anyone know how to do 7 days back? Thanks Link to comment https://forums.phpfreaks.com/topic/44925-week-before-date/ Share on other sites More sharing options...
hitman6003 Posted March 30, 2007 Share Posted March 30, 2007 echo date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"))); Link to comment https://forums.phpfreaks.com/topic/44925-week-before-date/#findComment-218149 Share on other sites More sharing options...
obsidian Posted March 30, 2007 Share Posted March 30, 2007 Check out strtotime() in more detail: <?php $timeStamp = strtotime("{$oLastBatchDate->Last} +7 day"); // 7 days ahead $timeStamp = strtotime("{$oLastBatchDate->Last} -7 day"); // 7 days behind ?> Link to comment https://forums.phpfreaks.com/topic/44925-week-before-date/#findComment-218154 Share on other sites More sharing options...
Daniel0 Posted March 30, 2007 Share Posted March 30, 2007 I know it would get the same result, but +/-1 week in strtotime would to it as well. strtotime can translate (almost) any formatted date into a timestamp and calculate relative to "now" or a specified date or timestamp. Link to comment https://forums.phpfreaks.com/topic/44925-week-before-date/#findComment-218158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.