Welcome to WebmasterWorld Guest from 23.20.79.227

Forum Moderators: open

Message Too Old, No Replies

Is this date query possible?

     
11:25 am on Jan 5, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2005
posts: 143
votes: 0


I'd like to have users input a 'start date' for a holiday. I'd like to show results for 2 days either side of the day they searched for. BUT prioritize dates matching their actual searched date first. Is this possible with one query?

Thanks

Tom
4:34 pm on Jan 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


This is probably in error by likely the right direction.

// Cleanse and store date in YYYY-MM-DD format "$date"

select * from table where datefield >= date_sub('$date', interval 2 day) and datefield <= date_add('$date', interval 2 day) order by datefield = '$date' desc, datefield desc;

The order by may need some work, but the idea is to use an expression in the first half of the clasue
9:32 am on Jan 6, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2005
posts: 143
votes: 0


Thank you! Never thought of doing it that way.

Much appreciated.