Change language

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.

// 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 


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method