0

Code :

<?php echo date('Y/m/d'); ?>

Echo : 2022/03/18

what i need is adding 3 days of the current day

any possible solution ?

Exemple :

the code will echo this :

2022/03/21

Nayfer
  • 1
  • 1

2 Answers2

0
<?php echo Date('y:m:d', strtotime('+3 days')); ?>
0
<?php
$date = date('Y/m/d');
echo date('Y-m-d', strtotime($date. ' + 3 days'));

Also there is a \Datetime class in PHP:

https://www.php.net/manual/en/class.datetime.php

https://www.php.net/manual/en/function.strtotime.php

You can for instance say:

+ 1 week

or

+ 2 days

or

- 3 years

The date() function gives the date string in specified format. So if on 31 december 2022 you say "+ 1 day" the date becomes 1 januari 2023.

If you then echo date("Y", strtotime("31 december 2022 + 1 day")) it will say "2023"

UnpassableWizard
  • 1,237
  • 11
  • 20
  • Thanks mate, also i got a question '+ 3 days' is php know that 'days' go to '/d' ? and 'years' go to '/y' etc.. ? – Nayfer Mar 18 '22 at 16:45
  • strtotime sort of makes sense of a lot of logic ways to specify a point in time. I will make an addition to the answer. – UnpassableWizard Mar 18 '22 at 16:49