totn Access

MS Access 2003: Set up a text box to display the difference between two dates (display value of 1 if dates are the same)

This MSAccess tutorial explains how to set up a text box to display the difference between two dates in Access 2003 (with screenshots and step-by-step instructions).

Question: In an Access 2003/XP/2000/97 Form or Report, I'd like to calculate/display the difference between 2 date fields (From_Date and To_Date). I want to display the number of days between 'From_Date' and 'To_Date', and if the dates are the same date, I'd like to display the result as 1.

Answer: You can create a Text Box on your Form or Report. Then set the Control Source property of the Text Box to the following formula:

=IIf([From_Date]=[To_Date],1,DateDiff("d",[From_Date],[To_Date]))

Microsoft Access