Fix DateDiff Invalid Syntax Error in Access Calculated Field
Question details
The user needs to calculate the number of days between two date fields but encounters an error when saving the expression in an Access table.
- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Attempting to use IIf, And, and DateDiff functions within a table calculated field to find the days between BR_Date_reported and BR_Date_deleted.
- Observed behavior
- Microsoft Access returns an Invalid Syntax error because calculated fields in tables have limited expression support.
Open your Access table in Design View and verify that both the BR_Date_reported and BR_Date_deleted fields are explicitly set to the 'Date/Time' data type before attempting any date calculations.
Move the DateDiff Calculation to an Access Query
Since Access table calculated fields do not fully support complex combinations of logical and DateDiff functions, moving the calculation to a query is the standard and most reliable method.
Queries are designed to handle complex expressions and data processing. Using your expression in a Select Query will bypass the syntax limitations of table-level calculated columns.
Go to the 'Create' tab on the Access ribbon and click on 'Query Design'. Add the table that contains your date fields to the query workspace.
Click inside an empty column in the Field row of the query design grid. Type your alias followed by a colon, then the expression: DaysBetween: IIf(Not IsNull([BR_Date_reported]) And Not IsNull([BR_Date_deleted]), DateDiff("d", [BR_Date_reported], [BR_Date_deleted]), Null).
Click the 'Run' button (the red exclamation mark) on the ribbon to execute the query and ensure the days are calculated properly without syntax errors.
Use the Expression as a Form Control Source
If you only need to display the calculated days on a user interface, you can apply the DateDiff expression directly within a form's text box.
Looking for an Easier Way to Calculate Data?
While Microsoft Access handles complex database management, many users find that standard data tracking and date calculations are easier to manage in spreadsheets. WPS Spreadsheet is a powerful, free tool that supports advanced date functions like DATEDIF without strict table syntax limitations.
- 1. Export Access Data: Export your Microsoft Access table to an Excel (.xlsx) file format.
- 2. Open with WPS Spreadsheet: Launch WPS Office and open your newly exported spreadsheet.
- 3. Calculate Dates Easily: Use the standard =DATEDIF() function in a new column to calculate the days between your two date columns effortlessly.

Frequently Asked Questions
Why does DateDiff cause an error in an Access table calculated field?
Table calculated fields in Access are designed for basic arithmetic and support only a limited subset of functions. They often reject complex logical operators paired with specific date functions like DateDiff, which are meant to be executed in queries or forms.
What is the correct syntax for calculating days between two dates in Access?
The core function is DateDiff("d", [StartDate], [EndDate]). It is best practice to wrap it in an IIf statement to handle null values and prevent errors if one of the date fields is empty.
Can I calculate dates in a table without using a query?
It is not recommended. Access tables are meant for raw data storage, not processing. Date differences and conditional logic should always be handled in queries, forms, or reports to maintain database integrity.




