Calculate Date Difference in Y, M, D format

P

Palacelaw

I want to calculate the difference between Opened_Date and Date_Completed in
Y, M, D format in a field called Number_Of_Open_Days with the following
conditions.

If Opened_Date is null then Number_Of_Open_Days should be null. If
Date_Completed is null then Number_Of_Open_Days should be the difference in
Y, M, D format between Today and Opened_Date.

I've tried various combinations of DateDiff with no luck.

Thanks in advance for your help.
 
M

Marshall Barton

Palacelaw said:
I want to calculate the difference between Opened_Date and Date_Completed in
Y, M, D format in a field called Number_Of_Open_Days with the following
conditions.

If Opened_Date is null then Number_Of_Open_Days should be null. If
Date_Completed is null then Number_Of_Open_Days should be the difference in
Y, M, D format between Today and Opened_Date.


Try using:
DateDiff("d", Nz(Date_Completed, Date()), Opened_Date)

I don't understand what you mean by
"the difference in Y, M, D format"
 
D

Drew

Marshall Barton said:
Try using:
DateDiff("d", Nz(Date_Completed, Date()), Opened_Date)

I don't understand what you mean by
"the difference in Y, M, D format"

To answer your question - for example if Opened Date is 1/1/2008 and Date
Completed is 2/2/2009 then Number of Open Days would be 1 year, 1 month, 1
day.
 
M

Marshall Barton

Drew said:
To answer your question - for example if Opened Date is 1/1/2008 and Date
Completed is 2/2/2009 then Number of Open Days would be 1 year, 1 month, 1
day.


Ahhh, then use Doug's fancy function. Make sure that you
use Nz(Date_Completed, Date()) to deal with Null completion
date.
 

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