Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    334
    Thanks
    63
    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.

    PHP Code:

    $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

    Last edited by paddyfields; 05-14-2012 at 09:53 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •