Forum Moderators: open

Message Too Old, No Replies

Compare multiple dates

         

Drummer_si

11:53 am on Dec 23, 2008 (gmt 0)

10+ Year Member



SELECT * FROM tbl_clients
WHERE (
clientQ1 < DATE_ADD( CURDATE(), INTERVAL 7 DAY ) OR
clientQ2 < DATE_ADD( CURDATE(), INTERVAL 7 DAY ) OR
clientQ3 < DATE_ADD( CURDATE(), INTERVAL 7 DAY ) OR
clientQ4 < DATE_ADD( CURDATE(), INTERVAL 7 DAY )
)

clientQ1-4 are date fields, and this query returns all clients whose dates fall within the next 7 days!

However, I need to know which one of those dates is the date in question - Note: It can only BE one date as they are roughly 3 months apart!

Does anyone have any ideas how to do this? I've tried SELECT and IF ELSE statements with no success :(

phranque

1:13 pm on Dec 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



do you need to know the column from which the date matched or the date from the matching column or both?

perhaps the answer is to make 4 queries.

Drummer_si

3:54 pm on Dec 23, 2008 (gmt 0)

10+ Year Member



phranque.. Either... Preferrably both.

LifeinAsia

4:21 pm on Dec 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



This should work:
SELECT clientQ1 AS TheDate, 'Q1' AS TheClient
FROM tbl_clients
clientQ1 < DATE_ADD( CURDATE(), INTERVAL 7 DAY )
UNION
SELECT clientQ2 AS TheDate, 'Q2' AS TheClient
FROM tbl_clients
clientQ2 < DATE_ADD( CURDATE(), INTERVAL 7 DAY )
UNION
SELECT clientQ3 AS TheDate, 'Q3' AS TheClient
FROM tbl_clients
clientQ3 < DATE_ADD( CURDATE(), INTERVAL 7 DAY )
UNION
SELECT clientQ4 AS TheDate, 'Q4' AS TheClient
FROM tbl_clients
clientQ4 < DATE_ADD( CURDATE(), INTERVAL 7 DAY )

"TheDate" will be the matching date and "TheClient" will be the value of the matching client (Q1, Q2, etc.).

[edited by: LifeinAsia at 4:22 pm (utc) on Dec. 23, 2008]