How do you subtract two dates in an expression?

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
 
S

strive4peace

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
 
P

Paul Ponzelli

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
 
S

strive4peace

you're welcome, Paul ;) happy to help

Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top