Adding days to $Date can be done in many ways. It is very easy to do by using built-in functions like strtotime(), date_add() in PHP.
Method 1: Using strtotime() Function: The strtotime() Function is used to convert an English textual date-time description to a UNIX timestamp.
strtotime( $EnglishDateTime, $time_now )
Parameters: This function accepts two optional parameters as mentioned above and described below.
- $EnglishDateTime: This parameter specifies the English textual date-time description, which represents the date or time to be returned.
- $time_now: This parameter specifies the timestamp used to calculate the returned value. It is an optional parameter.
Program: PHP program to add days to $Date in PHP using strtotime() function.
Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds.
Parameters: This function accepts two parameters as mentined above and described below:
- Object: It specifies the DateTime object returned by date_create() function.
- Interval: It specifies the DateInterval object.
Program: PHP program to add days to $Date in PHP using date_add() function.
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- Program to find the number of days between two dates in PHP
- PHP | Number of week days between two dates
- Calculating total number of Hours, Days, Minutes and Seconds between two dates in Golang
- PHP | Date and Time
- PHP program to change date format
- PHP | Converting string to Date and DateTime
- Convert timestamp to readable date/time in PHP
- PHP | Spreadsheet | Setting a date and/or time value in a cell
- PHP date() format when inserting into datetime in MySQL
- Sort a multidimensional array by date element in PHP
- How to get last day of a month from date in PHP ?
- PHP | Ds\Set add() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.