![]() |
Getting the dates between 2 dates
I need to figure out a way to get the dates between $startdate and $enddate. Then insert all of them in to a MySQL table. This is for a small events calendar i've developed.
I've come across this function, just not sure how to grab each individual date and insert it into the table. This is a simple snippet of code that will return an array of days between two dates. Code PHP Code:
Kawasaki@Nexuz |
Please use [php] or [highlight=php] tags around the phpcode. It will be easier for us to read your code then - thus making it easier for us to help you.
|
k, any ideas? What i want to accomplish is to be able to give a start date and end date and have it insert all of the dates from start to finish into the event table. Also Maybe if i had a startDate and then span # of days.
|
Assuming that dateA and dateB are unix timestamps representing dates where dateA < dateB, this should work:
PHP Code:
Convert timestamp A into days Convert timestamp B into days Get the difference Starting from the first day, represent that day plus 0 to the difference. It would, however, be more efficient to store the start date and the end date in the database and have the script (or the query) generate your dates opposed to inserting each one. |
You haven't provided much information on the database structure, but wouldn't it be more efficient to store the start and end date/time on a per-event basis and deal with which days an individual item covers in the frontend code? Unless there's a reason each day must be saved individually?..
|
| All times are GMT. The time now is 11:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0