curl_setopt($ch, CURLOPT_URL, 'https://example.com/report.php?start=2011-01-12&end=2011-01-19'); PHP: I am trying to access a report API and save a local copy of the report for the last week. I can do this okay but I have to change the dates in the URL above manually each day. What I would like to do is use PHP so that the date range is always the last 7 days. Is there an easy way to do this, I have been reading about strtotime and using -7 days and a bunch of other things but with my limited PHP knowledge I am not sure how to implement what I have read. Thanks a bunch.
Like this maybe: $todaysdate = date('Y-m-d'); $sevendays = date ( 'Y-m-d', strtotime ( '-7 days' . $date ) ); $url = "https://example.com/report.php?start=$sevendays&end=$todaysdate"; curl_setopt($ch, CURLOPT_URL, $url); //echo $url; PHP: