Query with dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Query with dates

Post 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
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Query with dates

Post by mattpointblank »

SELECT * FROM table WHERE start_date < CURRENT_TIMESTAMP() AND end_date > CURRENT_TIMESTAMP()
shaam
Forum Newbie
Posts: 20
Joined: Tue Jun 23, 2009 6:36 am

Re: Query with dates

Post by shaam »

hi,
Check it by using date difference method i.e dateDIFF(start_date,current date)

hopefully it works
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Query with dates

Post by Benjamin »

Duplicate - Locked
Locked