How to add days to $ Date in PHP?

Method 1: Using the strtotime() function: The strtotime() function is used to convert English a textual description of the date and time in a UNIX timestamp.Syntax:
strtotime ($EnglishDateTime, $time_now) 
Parameters:This function takes two optional parameters as above and described below.
  • $EnglishDateTime:This parameter specifies a textual description of the date and time to English, which represents the date or time to be returned.
  • $time_now:This parameter specifies the timelabel used to compute the return value. This is an optional parameter.
Program:PHP program to add days to $Date in PHP using the strtotime() function.< / p>
// PHP program for adding days to $Date 
// Declare the date $Date = "2019-05-10" ;  
// Add days to date and show them echo date ( ` Ymd` , strtotime ( $Date . `+ 10 days` ));  
2019-05 -20 
Method 2: using date_add() function: function date_add() is used to add days, months, years, hours, minutes and seconds.Syntax:
date_add (object, interval) ; 
Parameters:This function takes two parameters, as described above and described below:
  • Object:indicates the DateTime object returned by the date_create() function.
  • Interval:indicates a DateInterval object.
Program:PHP -program for adding days to $Date in PHP using date_add() function.
// PHP program added 10 days per date 
// Declare the date $date = date_create ( "2019-05-10" );  
// Use the date_add() function to add a date object date_add ( $date , date_interval_create_from_date_string ( "10 days" ));  
// Show added date echo date_format ( $date , "Ymd" );  
2019-05 -20 
Get Solution for free from DataCamp guru