I have a variable ($date) holding the start date of an event which is in this format:
2012-11-20 (YYYY-M-D)
And I have another variable ($duration) holding a number e.g ‘3’ which is number of days or duration of the event. How can i increment the day in the date variable by the duration variable and then display the event date in this format
20th - 23th November
Thanks!
Try this:
See php date() for more details
If you have
2012-11-20in a variable, you can do this:Two things to consider:
strtotime(). If you givestrtotime()an invalid date string, it will returnfalseE_NOTICEif the time zone is not valid, and/or aE_STRICTorE_WARNINGmessage if using the system settings or theTZenvironment variable. See also date_default_timezone_set()A more robust solution:
EDIT
You updated your question asking how to get a date range. For this, I’d recommend the following: