List of Date between two dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gowni
Forum Newbie
Posts: 7
Joined: Sat Sep 20, 2003 7:14 am
Contact:

List of Date between two dates

Post by gowni »

Hi friends ,

I am new to php . Can anyone help to get list of dates between 2 dates.

Thanks in advance
gowni
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I prefer using the highlevel time-functions of php even if it take a bit longer. They are very flexible.
e.g.

Code: Select all

<?php
$tsStart = strtotime("15 December 2003");
$tsEnd = strtotime("+1 week", $tsStart);

$dateStart = getdate($tsStart);

do
{
	$tsCurrent = mktime(
			$dateStart['hours'], $dateStart['minutes'], $dateStart['seconds'],
			$dateStart['mon'], $dateStart['mday'], $dateStart['year']
		);
		
	echo date('D M j Y', $tsCurrent), "\n";
	
	$dateStart['mday'] += 1; // mktime takes care of day-of-month values that are out-of-bound
}while($tsCurrent < $tsEnd);
?>
take a look at the manual pages of
strtotime()
getdate()
date()
mktime()
Post Reply