Jump to content

[SOLVED] find all dates between two dates


Evan69

Recommended Posts

Hi, im righting a calender script in which the events need to be over a period of several dates. Dates are in format of (YYYY-MM-DD). I will have the user enter a start date and an end date, i then need a script to find all the dates inbetween the start and end. Here is the script i have to find the difference between days, unforutanetly i cant think of a way to find the dates when the years or months are different.

Any help would be much appreciated.

 

<?php
//yyyy-mm-dd
$start = '2007-11-01';
$end = '2007-11-05';

//the start day is $start[2] and end day is $end[2]
$start = explode('-', $start);
$end = explode('-', $end);

for($i = $start[2]; $i <= $end[2]; $i++)
{
//there cant be any 1 digit numbers
if(strlen($i) < 2)
{
	$i = '0'.$i;
}
$dates .= $start[0].'-'.$start[1].'-'.$i.' ';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/78661-solved-find-all-dates-between-two-dates/
Share on other sites

<?php
$start = '2007-11-01';
$end = '2007-11-05';

$st = strtotime($start);
$et = strtotime($end);

while ($st <= $et)
{
    echo date ('Y-m-d', $st), '<br />';
    $st = strtotime ('+1 days', $st);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.