Date Ranges

Dealing with dates and temporal information in distributed applications is inherently difficult. Time zone and daylight savings time issues as well as synchronization between servers makes dealing with time information a challenging problem. Commonly, we encounter two uses of dates. First use deals with selecting records between two dates and second use deals with reporting and specifying reoccurring dates. How should these two situations be handled in a web application?

In the first situation I had to display a set of records in a data grid. Data displayed needed to fall within a date range selected from a combo box holding predefined date ranges named as follows: “Last month”, “Last six months”, etc. In order to select the requested records from the data store, the chosen item from the range combo box had to be converted to an actual pair of dates. In this situation, I had two choices. The range could have been calculated on the client side and passed to the server or it could have been calculated on the server side after passing a constant to the server from the client.

Calculating the date range on the client side appears to be a simpler solution on the surface. User selects a constant and dates are calculated for the “from” and “to” dates. The date range is passed to the back end. Dates are passed into a query and desired set of records is returned. In contrast, passing a constant to the server and calculating the date range is more complicated. In the server solution we have to make sure that we pass in the client’s time zone along with the constant in order to calculate the date range on the server in the client’s correct time zone.

Although second solution might be a bit more complicated due to the fact that not every client side language provides adequate facilities for calculating time zones, it offers a consistent solution when it comes to the second issue: dealing with reoccurring dates in reporting. Calculating date ranges on the server from constants allows us to use a consistent set of utilities for both reoccurring date range calculations as well as selecting sets of records falling within a desired date range chosen by the client.

Date Ranges

04/19/2014 - Paul Trzyna