will anyone please help?
Here is i would like to do.
If I know the starting date.
How can I find Mon, Wed & Fri in two weeks from my starting date eg startingdate is (2008-09-15)
and find Tuesday, Thurday & Sathurday from my starting date eg startingdate is (2008-09-16)
and Mon - Fri from my starting date eg startingdate is (2008-09-15)
Thank you very much for your help
color,
Find date help?
Moderator: General Moderators
Re: Find date help?
http://ca3.php.net/manual/en/function.date.php
Code: Select all
<?php
/*
@params $firstdate, $lastdate
@return array() of array(monday,sunday)
@description returns all the mondays and sundays of the given date range
*/
function get_week_intervals($fdate,$ldate)
{
list($year,$month,$day) = explode('-',$fdate);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$week=array();
//get the dayname of the first day
//if month = current month get the current date as the last day
if($month==date('m'))
{
$lastday = date('d');
}
else
{
$lastday = date('t', strtotime($fdate));
}
if((date('l',strtotime($fdate))) == 'Sunday')
{
$monday = $fdate;
$sunday = $fdate;
}
else
{
$monday = $fdate;
$sunday = date('Y-m-d',(mktime(date('H'),
date('i'),date('s'),$month,
$day,$year))-($daynum-7)*86400);
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
$day = date('d',strtotime($sunday." +1 day"));
while($sunday < $ldate)
{
$monday = date('Y-m-d',strtotime($sunday." +1 day"));
list($year,$month,$day) = explode('-',$monday);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$sunday = date('Y-m-d',(mktime(date('H'),date('i'),
date('s'),$month,$day,$year))-($daynum-7)*86400);
if($sunday > $ldate)
{
$sunday = $ldate;
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
}
return $week;
}
?>
Re: Find date help?
Thank you so much for your quick respond, I will give it a try and let you know
Thanks again Marc!
Thanks again Marc!
Re: Find date help?
Hi Mac - I did try this function like below and the result show = Array
Can you give some more adviser here,
Thanks alot
function get_week_intervals($fdate,$ldate)
{
list($year,$month,$day) = explode('-',$fdate);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$week=array();
//get the dayname of the first day
//if month = current month get the current date as the last day
if($month==date('m'))
{
$lastday = date('d');
}
else
{
$lastday = date('t', strtotime($fdate));
}
if((date('l',strtotime($fdate))) == 'Sunday')
{
$monday = $fdate;
$sunday = $fdate;
}
else
{
$monday = $fdate;
$sunday = date('Y-m-d',(mktime(date('H'),
date('i'),date('s'),$month,
$day,$year))-($daynum-7)*86400);
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
$day = date('d',strtotime($sunday." +1 day"));
while($sunday < $ldate)
{
$monday = date('Y-m-d',strtotime($sunday." +1 day"));
list($year,$month,$day) = explode('-',$monday);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$sunday = date('Y-m-d',(mktime(date('H'),date('i'),
date('s'),$month,$day,$year))-($daynum-7)*86400);
if($sunday > $ldate)
{
$sunday = $ldate;
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
}
return $week;
}
echo get_week_intervals("2007-08-08","2008-08-08");
Can you give some more adviser here,
Thanks alot
function get_week_intervals($fdate,$ldate)
{
list($year,$month,$day) = explode('-',$fdate);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$week=array();
//get the dayname of the first day
//if month = current month get the current date as the last day
if($month==date('m'))
{
$lastday = date('d');
}
else
{
$lastday = date('t', strtotime($fdate));
}
if((date('l',strtotime($fdate))) == 'Sunday')
{
$monday = $fdate;
$sunday = $fdate;
}
else
{
$monday = $fdate;
$sunday = date('Y-m-d',(mktime(date('H'),
date('i'),date('s'),$month,
$day,$year))-($daynum-7)*86400);
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
$day = date('d',strtotime($sunday." +1 day"));
while($sunday < $ldate)
{
$monday = date('Y-m-d',strtotime($sunday." +1 day"));
list($year,$month,$day) = explode('-',$monday);
$daynum = date('w',
mktime(date('H'),
date('i'),
date('s'),
$month,
$day,
$year)
);
$daynum = $daynum==0? 7 : $daynum;
$sunday = date('Y-m-d',(mktime(date('H'),date('i'),
date('s'),$month,$day,$year))-($daynum-7)*86400);
if($sunday > $ldate)
{
$sunday = $ldate;
}
$week[] = array('monday'=>$monday,'sunday'=>$sunday);
}
return $week;
}
echo get_week_intervals("2007-08-08","2008-08-08");
Re: Find date help?
I didn't really look at the code I posted--I just copied it from the PHP.net site.
It appears like the returned value is an array. try outputting it like:
It appears like the returned value is an array. try outputting it like:
Code: Select all
echo '<pre>';
print_r(get_week_intervals("2007-08-08","2008-08-08"));
echo '</pre>';
Re: Find date help?
it's working,
Thank you so much!!!!! Marc,
Thank you so much!!!!! Marc,
Re: Find date help?
Hi Marc, I really need your help again. Base on this example I try to find Monday, Wednesday, and Friday, But I could not have it to work, Will you help me on this,
Thanks alot,
color
Thanks alot,
color
Re: Find date help?
Take a look at the php.net website; and you will understand everything!