# Filter a Table by Date/Time

A table can be filtered based on a product type and a date range, to display the most recent result first.

1. Configure the database.

   1. Ensure that an index for the table has been correctly configured.

      Note: See the Create an Index for a SQLite Database topic for more information.

   2. Create a query with the following in the Query Text field:

      SELECT * FROM #TABLE

      WHERE Timestamp < @ToDate AND Timestamp >= @FromDate AND ProductType=@ProductType

      ORDER BY Timestamp DESC

   3. From the Query Builder dialog, press the Advanced button and enable the Update Query on Parameter Changed parameter.

      Note: See the Advanced Query Options topic for more information.
   4. Set the Delay before triggering parameter to a value (e.g. 50), otherwise the script code that will be instituted later will cause the query to execute twice.

2. On a Page, from the Page User Inputs, add two DateTime Entryelements.

   1. Set both of the DateTime Entry elements Date Format property to display the ShortDate format:

   2. One of the DateTime Entry elements will be configured for the database's FromDate parameter, and the other DateTime Entry element will be for the ToDate parameter.

      1. Configure the Value property of the first DateTime Entry to the database's FromDate parameter tag:

      2. Configure the Value property of the second DateTime Entry to the database's ToDate parameter tag:

3. When using dates as parameters, it is important to note that they have a time field, as well. The time field must be correctly configured via script.

   1. In a User Scripts (or in the OnStartup script), enter similar code:

          // Query defaults
          $Databases.FastDatabase.Results.DateSearch.Parameters.FromDate = DateTime.Now.Date.AddDays(-7);
          $Databases.FastDatabase.Results.DateSearch.Parameters.ToDate = DateTime.Now.Date.AddDays(1).AddTicks(-1);