Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL select by date?

  • 30-03-2006 3:24pm
    #1
    Closed Accounts Posts: 8,866 ✭✭✭


    I have a page that prints different results from a table based on criteria specified in the previous page. On of the options is selecting results where they are due in 2 weeks, so I need syntax to select all where date is less than or equal to two weeks from whatever the current date happens to be. So the syntax will look like this:

    [PHP]if($v==2){

    $SQL="SELECT * FROM tbl_renewal INNER JOIN tbl_customer ON
    rnwl_customer_id=customer_id INNER JOIN tbl_renewal_status ON rnwl_status_id=rs_id WHERE
    rnwl_customer_id={$_SESSION} AND rnwl_firm_id={$_SESSION} AND
    rnwl_date<=(ENTER SYNTAX HERE)";[/PHP]

    Any help? Cheers


Comments

  • Registered Users, Registered Users 2 Posts: 3,889 ✭✭✭cgarvey


    If it's a recent MySQL, then something like
    DATE_ADD( NOW(), INTERVAL 14 DAY )
    
    (yes, that's day singular) should work.. check out the date functions section of the MySQL manual for more.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Yeah that looks good, but I just realised I need to make it a BETWEEN statement dont i? if i use rnwl_date<=DATE_ADD( NOW(), INTERVAL 14 DAY ) it gives me everything before two weeks from now...where as I only want results between NOW() and two weeks from now... would rnwl_date BETWEEN( NOW () AND INTERVAL 14 DAY) work?


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Never mind, I got it:

    SELECT * FROM tbl_renewal WHERE rnwl_date>CURDATE() AND rnwl_date<=DATE_ADD( NOW(), INTERVAL 14 DAY )

    Cheers cgarvey, you put me on the right track!


  • Registered Users, Registered Users 2 Posts: 2,758 ✭✭✭Peace


    I would tend to use the BETWEEN operator for that sort of thing.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    True, when I tried it first with the BETWEEN i had the syntax terribly wrong and assumed it didnt work, i've fixed that now.


  • Advertisement
Advertisement