03-13-2009, 07:11 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Mar 2009
Posts: 2
Thanks: 0
|
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:
<?php function GetDays($sStartDate, $sEndDate){ // Firstly, format the provided dates. // This function works best with YYYY-MM-DD // but other date formats will work thanks // to strtotime(). $sStartDate = gmdate("Y-m-d", strtotime($sStartDate)); $sEndDate = gmdate("Y-m-d", strtotime($sEndDate)); // Start the variable off with the start date $aDays[] = $sStartDate; // Set a 'temp' variable, sCurrentDate, with // the start date - before beginning the loop $sCurrentDate = $sStartDate; // While the current date is less than the end date while($sCurrentDate < $sEndDate){ // Add a day to the current date $sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate))); // Add this new day to the aDays array $aDays[] = $sCurrentDate; } // Once the loop has finished, return the // array of days. return $aDays; } ?>
Any Ideas? This is for inserting entries into a calendar FROMdate TOdate. Know what i mean? Thank you for your suggestions.
Kawasaki@Nexuz
Last edited by kawasaki : 03-14-2009 at 03:34 PM.
|
|
|
|