Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Find data 'This Weekend'
05-14-2012, 10:50 PM #1
- Join Date
- Dec 2010
- Thanked 11 Times in 11 Posts
Find data 'This Weekend'
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'));
$friday = date('Y-m-d',strtotime('next Friday, 11:59am'));
if($findDay == 'Sunday')
$sunday = date('Y-m-d',time());
$sunday = date('Y-m-d',strtotime('next Sunday, 12pm'));
WHERE event BETWEEN $friday AND $sunday
Last edited by paddyfields; 05-14-2012 at 10:53 PM.