Php now plus 1 day
In certain situations I want to add 1 day to the value of my DATETIME formatted variable: Show
What is the best way to do this?
John Conde 215k98 gold badges447 silver badges489 bronze badges asked Aug 17, 2009 at 5:20
There's more then one way to do this with DateTime which was introduced in PHP 5.2. Unlike using
Jasper 75.3k13 gold badges149 silver badges145 bronze badges answered Jan 31, 2013 at 1:57
John CondeJohn Conde 215k98 gold badges447 silver badges489 bronze badges 3 If you want to do this in PHP:
If you want to add the date in MySQL:
answered Aug 17, 2009 at 5:23
RaYellRaYell 68.5k20 gold badges125 silver badges150 bronze badges 3 The DateTime constructor takes a parameter There are some valid values as examples :
So, in your case you can use the following.
AnthonyB 1,9621 gold badge20 silver badges28 bronze badges answered Sep 15, 2016 at 10:20
DmitryDmitry 4595 silver badges4 bronze badges 1
eg:
If it's only adding 1 day, then using strtotime again is probably overkill. answered Aug 17, 2009 at 5:27
nickfnickf 525k198 gold badges640 silver badges720 bronze badges 3 You can use
answered Aug 1, 2019 at 10:43
OmarOmar 86611 silver badges12 bronze badges You can use as following.
You can also set days as constant and use like below.
answered Oct 29, 2019 at 5:50
user3216114user3216114 1893 silver badges13 bronze badges I suggest start using Zend_Date classes from Zend Framework. I know, its a bit offtopic, but I'll like this way :-)
answered Aug 17, 2009 at 5:39
PawkaPawka 2,5043 gold badges24 silver badges32 bronze badges 1 Using server request time to Add days. Working as expected. 25/08/19 => 27/09/19
Here '+2 days' to add any number of days. answered Aug 25, 2019 at 17:02
NiroshanNiroshan 3113 silver badges4 bronze badges There is a more concise and intuitive way to add days to php date. Don't get me wrong, those php expressions are great, but you always have to google how to treat them. I miss auto-completion facility for that. Here is how I like to handle those cases:
For me, it's way more intuitive and autocompletion works out of the box. No need to google for the solution each time. As a nice bonus, you don't have to worry about formatting the resulting value, it's already is ISO8601 format. This is meringue library, there are more examples here. answered May 16, 2020 at 16:30
Vadim SamokhinVadim Samokhin 3,3144 gold badges39 silver badges66 bronze badges One liner !
answered Sep 19 at 15:41
Brain90Brain90 1,45318 silver badges21 bronze badges How do I add 1 day to a date?const date = new Date('2022-02-21'); const dateCopy = new Date(date. getTime()); dateCopy. setDate(dateCopy. getDate() + 1); // 👇️ Tue Feb 22 2022 console.
How can get current date plus one day in PHP?this tutorial will give you example of add day to current date using php. $NewDate=Date('d:m:Y', strtotime('+1 days')); echo($NewDate);
How can I get todays date and yesterday in PHP?Get Yesterday's Date in PHP. date() in PHP.. DateInterval in PHP.. Using strtotime() to Get Yesterday's Date in PHP.. Using mktime() to Get Yesterday's Date in PHP.. Using time() to Get Yesterday's Date in PHP.. Using DateInterval to Get Yesterday's Date in PHP.. How can I get 30 day date in PHP?echo date('m/d/Y',strtotime('+30 days',strtotime('05/06/2016'))) . PHP_EOL; This will return 06/06/2016 . Am assuming your initial date was in m/d/Y format.
|