Ms-access – Query that compares dates

database-designms accesstable

I'm trying to create a query that shows if students are mature or not, based on their date of birth. However when the query is executed it returns all students as not mature. Any students that are born before 1/10/1971 should be classed as mature.

Shown below is the IIf() statement I have used to show if students are mature.

enter image description here

When executed the table returns the following results

enter image description here

Can anyone give any idea as to why this is happening?

Shown below is the full page of the Query

enter image description here

Best Answer

Most likely because the expression 1/10/1971 is interpreted as a numeric expression, i.e. 1 divided by 10 divided by 1971 which is 0 (with integer division rounding values down). Telling Access that this is a date can be done using quotes (not really recommended) or by using a date function, like this:

IIf([DOB]<DateSerial(1971, 10, 1), "Mature", "Not mature")

The above DateSerial() VBA function will return October 1, 1971. The parameters are (Year, Month, Day).

Also, the following will work (thanks, @ypercube!)

IIf([DOB]<#1971-10-01#, "Mature", "Not mature")