add 2 weeks with current date in php

To add 2 weeks to the current date using PHP, you can use the DateTime class and the add() method with the DateInterval class.

Here's an example code snippet:

main.php
$currentDate = new DateTime();
$twoWeeksLater = $currentDate->add(new DateInterval('P2W'));
echo $twoWeeksLater->format('Y-m-d'); // outputs date 2 weeks from now in yyyy-mm-dd format
184 chars
4 lines

The add() method takes a DateInterval object as its parameter. In the example above, we create a new DateInterval object representing a duration of 2 weeks using the P2W format string. Finally, we use the format() method to output the date 2 weeks from now in the desired format.

related categories

gistlibby LogSnag