Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the number of days from two dates

Status
Not open for further replies.

10TR

Technical User
Dec 14, 2009
12
US
Hello,

I am try to get the number of days only from two dates in an Access query. I need the days to calculate depreciation for an asset. It works fine in Excel but I am getting the wrong number in Access.

DATEDIF(C9,$B$4,"md" = 5 Days
Date1 = 7/26/2008
Date2 = 3/31/2011
DateDiff("d",[DateAcquired],[DepreciationDate]) = 1344

3 years 8 months 5 days

I need Access to give me the 5 days.

Any help would be appreciated.

Thanks

Tony
 

How did you get 1344?
Code:
MsgBox DateDiff("d", "7/26/2008", "3/31/2011") [green]'= 978[/green]

I got 798 days

Have fun.

---- Andy
 
I am using this calculation within a query. I don't know where it was getting that number. I was able to make a change and use DatePart and get the results needed.

DatePart("d",[DepreciationDate])-DatePart("d",[DateAcquired])

The numbers are coming out correct now. Here is the rest of the expression.

IIf(DatePart("d",[DepreciationDate])-DatePart("d",[DateAcquired])<=15,(DateDiff("m",[DateAcquired],[DepreciationDate])-1)*(SLN([PurchasePrice],([SalvageValue]+[Sec 179 Exp]),[DepreciableLife])/12),DateDiff("m",[DateAcquired],[DepreciationDate])*(SLN([PurchasePrice],([SalvageValue]+[Sec 179 Exp]),[DepreciableLife])/12))

Thanks for your help!!

Tony
 
are you doing it in MS ACCESS (this forum) or excel (e.gthe syntax of your statement above?)

datepart (in MS ACCESS) accepte one date argument and returns the "part" of the date specified in the first argument, e.g.

Code:
? datepart("d", #7/26/2008#)
 26 

? datepart("m", #7/26/2008#)
 7 

? datepart("yyyy", #7/26/2008#)
 2008

you may get different answers in the 'correct" forum



MichaelRed


 
I must be missing something.

With data like
ID date1 date2
1 7/8/2011 7/7/2011
2 7/8/2011 7/7/2010
3 7/8/2011 1/2/2009
4 7/6/2009 8/26/2003

A query like
SELECT id, date1-date2
FROM dates;

produces the date differences doesn't it?

id Expr1001
1 1
2 366
3 917
4 2141

??


Even
SELECT dates.id, Format(Now()-date2,".00") AS Expr1
FROM dates;

if you wanted.
 

Look like [red]Excel[/red] to me
[tt]
DATEDIF([red]C9,$B$4[/red],"
[/tt]
Forum68

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top