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 6 of 6
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    Anyone knows how to query according to the date..

    Id like to have a query depending on what is the date today. Its like a sort of reminder.

    example. I have insert an action "Call Mr. Smith" and the date assigned is 2007-08-29 so by tommorow when i open my list of actions it will appear the the said "Call Mr. Smith" .

    my query is

    Select * from schedule where enddate<=NOW()

    but this query will display all the enddate that less than 2007..

    Thanks..

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    $datenow date("Y-m-d");
    $sql "SELECT * FROM schedule WHERE enddate = '$datenow'"
    or

    PHP Code:
    $sql "SELECT * FROM schedule WHERE enddate >= '$datenow 00:00'  AND enddate <= '$datenow 23:59'"
    depends whether field is date or datetime
    Last edited by Bahamut; 08-28-2007 at 10:49 AM.

  • #3
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    what if i want to display list of actions which less than end date assigned..

    heres the scenario..

    start dates
    2007-08-23 - meeting
    2007-08-24 - call smith
    2007-08-25- 1st interview
    2007-08-26- 2nd inteview

    end date
    2007-08-25- meeting
    2007-08-29- call smith
    2007-08-28-1st interview
    2007-08-31-2nd interview

    the very end date is 2007-08-31, therefore the actions displays are from 2007-08-28 to 2007-08-31, or todays date to very last date..

    tnx

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    $sql "SELECT * FROM schedule WHERE startdate >= '$datenow' OR enddate >= '$datenow'"

  • Users who have thanked Bahamut for this post:

    che_anj (08-28-2007)

  • #5
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Thanks Bahamut..

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You can use the SQL function CURDATE() instead of using a PHP function:

    PHP Code:
    $sql "SELECT * FROM schedule WHERE startdate >= CURDATE() OR enddate >= CURDATE();"

  • Users who have thanked Mwnciau for this post:

    che_anj (08-28-2007)


  •  

    Posting Permissions

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