paddyfields
05-14-2012, 09:50 PM
Hi, just thought I'd post this incase it's useful to anyone. Took me enough time to work out so may reduce a headache for someone!
If you need to pull data from your database for events that are happening 'this weekend', Friday - Sunday inclusive, then this works a treat. If the current day is Friday, Saturday, or Sunday then it will find data from the current weekend, however if it is a Monday-Thursday then it will find data from the upcoming weekend.
Hopefully the way I've explained that makes sense.
$findDay = date('l');
if($findDay == 'Friday')
{
$friday = date('Y-m-d',time());
}
elseif($findDay == 'Saturday'|| $findDay =='Sunday')
{
$friday = date('Y-m-d',strtotime('last Friday, 11:59am'));
}
else
{
$friday = date('Y-m-d',strtotime('next Friday, 11:59am'));
}
if($findDay == 'Sunday')
{
$sunday = date('Y-m-d',time());
}
else
{
$sunday = date('Y-m-d',strtotime('next Sunday, 12pm'));
}
This would then be used in your SQL query such as WHERE event BETWEEN $friday AND $sunday
:eek:
If you need to pull data from your database for events that are happening 'this weekend', Friday - Sunday inclusive, then this works a treat. If the current day is Friday, Saturday, or Sunday then it will find data from the current weekend, however if it is a Monday-Thursday then it will find data from the upcoming weekend.
Hopefully the way I've explained that makes sense.
$findDay = date('l');
if($findDay == 'Friday')
{
$friday = date('Y-m-d',time());
}
elseif($findDay == 'Saturday'|| $findDay =='Sunday')
{
$friday = date('Y-m-d',strtotime('last Friday, 11:59am'));
}
else
{
$friday = date('Y-m-d',strtotime('next Friday, 11:59am'));
}
if($findDay == 'Sunday')
{
$sunday = date('Y-m-d',time());
}
else
{
$sunday = date('Y-m-d',strtotime('next Sunday, 12pm'));
}
This would then be used in your SQL query such as WHERE event BETWEEN $friday AND $sunday
:eek: