Page 1 of 1

Query with dates

Posted: Wed Jun 24, 2009 3:19 am
by kerepuki
Hey guys,

I have been trying to figure out how to return a set of results based on 2 dates which are store in my table.

I have a start_date and an end_date.

I want to grab all records which have a start_date less than now and an end_date greater than now. If end_date is less than now I want to exclude the records from the result set
I have already taken the required procedures to ensure the end_date cannot be less than start_date.

Thanks in advance

Re: Query with dates

Posted: Wed Jun 24, 2009 5:26 am
by mattpointblank
SELECT * FROM table WHERE start_date < CURRENT_TIMESTAMP() AND end_date > CURRENT_TIMESTAMP()

Re: Query with dates

Posted: Wed Jun 24, 2009 5:30 am
by shaam
hi,
Check it by using date difference method i.e dateDIFF(start_date,current date)

hopefully it works

Re: Query with dates

Posted: Wed Jun 24, 2009 10:39 am
by Benjamin
Duplicate - Locked