Jump to content

[SOLVED] How to get days between two dates?


t_machine

Recommended Posts

Hi, I am using the following function to get the actual days between two given dates but it is having memory allocation issues.

 

 


$sStartDate = 2009-06-22;
$sEndDate = 2009-06-29;

function _GetDays($sStartDate, $sEndDate){
  $sStartDate = gmdate("Y-m-d", strtotime($sStartDate));
  $sEndDate = gmdate("Y-m-d", strtotime($sEndDate));
  $aDays[] = $sStartDate;
  $sCurrentDate = $sStartDate;
  
  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;
  }
  return $aDays;
}//EOF

 

What I am trying to do is get it to display 2009-06-22, ..23, ..24, 25, 26, 27, 28 and the 2009-06-29. This would be the days in between the start and end date  including both dates.

 

Any help or a better code would be really appreciated.

 

Thanks :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.