Searching on dates
Today I had a request to implement date-range searching functionality on an existing app that I wrote.
After looking around the web for ideas on how other do this I decided to go down the path of implementing a more "heuristic" style interface that the standard dropdown boxes or popup calendars. Below is how I planned to implement the data entry/UI side of things. I'd be interested to hear of any other interesting alternatives for taking user input for date range searching.
Client Request
Add a the ability for users to filter records by date
UI implementation
Textbox (initially blank) that allows a user to enter a date and allows users to filter records by date range.
A dropdown list that allows a user to select a date searching option, valid options are:
- Exact date
- Before date
- After date
- Surrounding week
- Surrounding month
- Surrounding 6 months
- Surrounding 12 months
Validation requirements
Client side validation that the date is valid
Dropdown list "disabled" if textbox is blank
Server-side implementation
- If no date is entered return resultset for all dates
Else
- If 'Exact date' is selected @startDate = [chosen date] 00:00:01 @endDate = [chosen date] 12:59:59
- If 'Before date' is selected @startDate = 1900-01-01 00:00:01 @endDate = [chosen date] 12:59:59
- If 'After date' is selected @startDate = [chosen date] 00:00:01 @endDate = 2099-12-01 12:59:59
- If 'Surrounding week' is selected @startDate = ([chosen date] - 7Days) 00:00:01 @endDate = ([chosen date] + 7Days) 12:59:59
- If 'Surrounding month' is selected @startDate = ([chosen date] - 1Month) 00:00:01 @endDate = ([chosen date] + 1Months) 12:59:59
- If 'Surrounding 6 months' is selected @startDate = ([chosen date] - 6Months) 00:00:01 @endDate = ([chosen date] + 6Months) 12:59:59
- If 'Surrounding 12 months' is selected @startDate = ([chosen date] - 12Months) 00:00:01 @endDate = ([chosen date] + 12Months) 12:59:59