homepage Welcome to WebmasterWorld Guest from 54.198.185.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Is this date query possible?
Elric99




msg:4404003
 11:25 am on Jan 5, 2012 (gmt 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

 

rocknbil




msg:4404092
 4:34 pm on Jan 5, 2012 (gmt 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

Elric99




msg:4404381
 9:32 am on Jan 6, 2012 (gmt 0)

Thank you! Never thought of doing it that way.

Much appreciated.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved