Add number of days to a date in php

705 Views

Add number of days to a date in php

Simple and easy way to add some days in a given date using strtotime function.

 <?php
$p_date = "2019-01-10";
echo date('Y-m-d', strtotime($p_date . ' + 1 days'));
echo date('Y-m-d', strtotime($p_date . ' + 15 days'));
echo date('Y-m-d', strtotime($p_date . ' + 30 days'));
?>

Basically date_add() function is  use for adding some days, months, years, hours, minutes, and seconds to a date in php.

date_add(object,interval);
 <?php
$date=date_create("2019-01-10");
date_add($date,date_interval_create_from_date_string("30 days"));
echo date_format($date,"Y-m-d");
?>

 

Tags:-
PHP

Today spacial posts