Date in PHP +3 weeks considering the current time
Get the solution ↓↓↓Help me calculate the next sale date using PHP.
Start date January 10, 2020 Sale happens every 3 weeks on Friday. How do I get the next sale date given the current date?
$start_date = "2020/01/10";
$date = strtotime($start_date);
$date = strtotime("+3 week", $date);
if current date next sale date
Answer
Solution:
$start_date = "2020/01/10";
$date = strtotime($start_date);
$date = strtotime("+3 week +1 day", $date);
$d = gmdate('Y/m/d D',$date);
while (substr($d,0,4)=="2020") {
echo $d."\n";
$date = strtotime("+3 week ", $date);
$d = gmdate('Y/m/d D',$date);
}
this will result in a list like this:
2020/01/31 Fri
2020/02/21 Fri
2020/03/13 Fri
2020/04/03 Fri
2020/04/24 Fri
2020/05/15 Fri
2020/06/05 Fri
2020/06/26 Fri
2020/07/17 Fri
2020/08/07 Fri
2020/08/28 Fri
2020/09/18 Fri
2020/10/09 Fri
2020/10/30 Fri
2020/11/20 Fri
2020/12/11 Fri
The+1 day
is to correct something to do with timezones...
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the browser (or proxy) sent a request that this server could not understand.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.