Appearance
Add 30 days to date
In PHP, you can add 30 days to a date by using the DateTime class and the modify() method. Here is an example of how to do this:
Example of adding 30 days to a date with the DateTime class and the modify() method
php
<?php
$date = new DateTime();
$newDate = $date->modify('+30 days');
echo $newDate->format('Y-m-d');
<div class="alert alert-info flex not-prose">Watch a video course Learn object oriented PHP
</div>
You can also use the add() method instead of modify() method, which takes a DateInterval object as its argument. Here is an example:
Example of adding 30 days to a date with the DateTime class and the add() method
php
<?php
$date = new DateTime();
$interval = new DateInterval('P30D');
$date->add($interval);
echo $date->format('Y-m-d');Both of the above examples will output the date 30 days from the current date in the format 'Y-m-d'.