fork download
  1. <?php
  2.  
  3. $today = new DateTime();
  4.  
  5. $updatetime = '19/01/2021'; // $table['renew']; //19/01/2021
  6. $updatetype = 'weekly'; //$table['type']; //daily || weekly || monthly
  7.  
  8. $updatetime = (new DateTime())->createFromFormat('d/m/Y', '19/01/2021');
  9.  
  10. // what I've done for weekly and seems to be working
  11. if($updatetime < $today){
  12. //$updatetime = $today; // reset to today
  13. $updatetime->modify('next week'); // add one week
  14. } else {
  15. return;
  16. }
  17.  
  18. echo 'Next time of weekly update '. $updatetime->format('Y-m-d') . PHP_EOL . PHP_EOL;
  19.  
  20.  
  21. echo 'Other examples of date manipulation using relative formats:'. PHP_EOL;
  22. $today = '2022-02-28';
  23.  
  24. $t = new DateTime($today);
  25.  
  26. // print the source date time
  27. echo $t->format('Y-m-d') . PHP_EOL;
  28.  
  29. // examples of continuously manipulate the date time origin
  30. echo $t->modify('next week')->format('Y-m-d') . PHP_EOL;
  31. echo $t->modify('next month')->format('Y-m-d') . PHP_EOL;
  32. echo $t->modify('next year')->format('Y-m-d') . PHP_EOL;
  33. echo $t->modify('next sunday')->format('Y-m-d') . PHP_EOL;
  34.  
  35.  
Success #stdin #stdout 0.02s 26708KB
stdin
Standard input is empty
stdout
Next time of weekly update 2021-01-25

Other examples of date manipulation using relative formats:
2022-02-28
2022-03-07
2022-04-07
2023-04-07
2023-04-09