[SOLVED] Add X days in a date
I'm trying to add days in a specific date. So, let's say we have the date in a string format: "07.05.2016", and I want to add 45 days, so it would become "21.06.2016" (again a string). Is there any efficient way of doing this?
|
Re: Add X days in a date
You can do this using the Unix Time include.
With this you can add or subtract days to/from a date using a positive or negative number as iDaysToAdd, respectively. I included functions to do this to a date string or to a date value in integer format. The date string must be in 'DD.MM.YYYY' format for this to work properly. Output: Code:
New date=12.05.2016PHP Code:
|
Re: Add X days in a date
First convert it to a timestamp, add the appropriate number of seconds and then reconvert it it a date.
|
Re: Add X days in a date
Thank you bugsy, that worked perfectly.
Thank you too, fysiks. |
Re: Add X days in a date
Bugsy, AMXX has natives for dealing with that, you don't need custom include.
PHP Code:
An example: PHP Code:
|
Re: Add X days in a date
I thought there might be built-in stuff, but couldn't think of the function name.
|
Re: Add X days in a date
Thank you, HamletEagle. That does look better and works just as well. I will stick to your method, since it doesn't require any additional includes.
|
| All times are GMT -4. The time now is 18:38. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.