TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-13-2009, 07:11 PM   #1 (permalink)
The Visitor
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
kawasaki is on a distinguished road
Default 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.
kawasaki is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the distance between 2 dates... may Advanced PHP Programming 18 06-08-2008 04:01 AM
Most efficient way of playing with dates? bdm Absolute Beginners 6 12-14-2007 01:36 PM
How to find difference between dates? Haris Absolute Beginners 2 10-06-2007 07:47 PM
Tutorial - Getting th, st and rd (ordinal suffixes) on numbers and dates serversphere Tips & Tricks 2 04-04-2007 10:06 AM


All times are GMT. The time now is 03:58 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design