Jump to content

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);
}
?>

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.