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 5 of 5

Thread: date headache.

  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts

    date headache.

    Hi there.

    I'm trying to create my own search function for users to search for events between certain dates. One option I have is 'within next 7 days'.

    So, within the SQL function I am searching "... WHERE eventdate between $from and $to.."

    The $from variable I figured would be $from = date('d-m-Y',time()); (ie- todays date)... but how would I find the date in 7 days?. I've seen strtotime mentioned about the web but can't figure how this applies.

    Any help would be marvelous!

    Cheers,
    Paddyfields.

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    PHP Code:
    $timenow time();
    $timeinaweek strtotime('+7 days'); 
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • Users who have thanked Lamped for this post:

    paddyfields (12-05-2010)

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Brilliant, thank you.

    Also, is there anyway to find the date this weekend as well, ie - a strtotime('thisweekend') sort of thing, to find the date of the closest Saturday.

  • #4
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    333
    Thanks
    63
    Thanked 11 Times in 11 Posts
    strtotime('next Saturday')

  • #5
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    date('w') should return the day of the week, 0 being Sunday, so...

    PHP Code:
    $saturday strtotime('-'.(date('w'$datetoprocess)+1).' days'$datetoprocess); 
    Untested, though something like that.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

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