in PHP I need to generate two ISO 8601 dates for an API, one needs to be the current date, and the other needs to be 3 days in the past. How do I do this? I can’t find any other good solutions on the internet.
>Solution :
You can use time() and subtract:
$currentDate = date('c');
$threeDaysAgo = date('c', time() - 3600 * 24 * 3);
or, using DateTime:
$threeDaysAgo = new DateTime();
$threeDaysAgo->modify("-3 days");
echo $threeDaysAgo->format("c");