Using a date constant in a query


When using a date constant, e.g. 25-Jan-1985, in a query, it requires special delimiters to be recognized as a date value. We use the same date format for the constant as we recommend for database fields and spreadsheet columns. See: Date format and configuration.


EXAMPLE DATABASE: World

DATA INPUT

Table politics in the database World.mdb is used as input.



QUERY date_constant

SELECT country, independence, government
FROM politics
WHERE independence IS NOT NULL AND
      independence >= #02-Sep-1939# AND
      independence <= #03-Sep-1945#; 

Query date_constant produces the output below which shows four records of countries that gained independence during World War II, during the period from 2nd September 1939 to 3rd September 1945.



DISCUSSION

The field independence contains date-type values which are compared with date constants in the query. When using a date constant in a query, the date value needs to be delimited with the # character in order to be correctly interpreted as a date. We strongly recommend using the unambiguous date format dd-mmm-yyyy as shown in the query example.


Last modified September 23, 2008 3:21 am