How do you subtract two dates in an expression?

  • Thread starter Thread starter Paul Ponzelli
  • Start date Start date
P

Paul Ponzelli

I'm trying to calculate the number of days that have elapsed between two
dates:

1. a date field named Target, and
2. today's date.

I've tried using expressions like

Date()-[Target] and
Val(Date)-Val[Target]

but I get the #Error result.

How can I write an expression that will return the number of days between
the two dates expressed as an integer?

Thanks in advance,

Paul
 
Hi Paul,

Where are you putting the equation?

Date()-[Target]
is valid if Target is a date

if this is in a form Controlsource, you need to preface the
equation with an equal sign

The DateDiff function is commonly used to get the number of
days between 2 dates as a date can also have a time

In a query:
DateDiff("d",[DateField],Date())

On a form or report:
=DateDiff("d",[DateControlname],Date())

where DateField is on the form/report (its Visible property
can be false) and DateControlname is the NAME property of
the control


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
That DateDiff() function is exactly what I needed. (I'm using it as a query
expression).

Thanks also for the detailed syntax for putting it in a form or report
control. I'm going to try it that was as well.

Thanks for your help, Crystal.

Paul
 
you're welcome, Paul ;) happy to help

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 
Back
Top