PDA

Click to See Complete Forum and Search --> : Calculating between 2 dates


ecohen007
Jan 13th, 2004, 01:52 PM
Hi everyone,
i'm working with msaccess forms.
I have 2 dates: date1 - date2
For example, date1= #01/01/2003# and date2= #03/01/2004#
I used dateresult= -datediff("y",[date2],[date1]) and it's just gives me dateresult = 1
I want to get as a result the number of years, the number of months and number of days.
Please I need your help.

Sorry for my bad english!

Pasvorto
Jan 14th, 2004, 12:05 PM
how about

years = datediff("yyyy",date1,date2)
months = (years * 12) - datediff("m",date1,date2)

I'm not sure about the days

dnrodrigo
Jan 14th, 2004, 10:48 PM
Years = DateDiff("yyyy", Date1, Date2)
Months = DateDiff("m", Date1, Date2)
Days = DateDiff("d", Date1, Date2)

Matt_T_hat
Jan 15th, 2004, 04:39 AM
whats wrong with temp=Date1 - Date2? the result should be a value that expresses a time span in VB one would then take Hour(temp) Day(temp) Year(temp)...

It's pritty much the same but I was just wondering.

Pasvorto
Jan 15th, 2004, 12:34 PM
Wouldn't that just give you the same time amount only expressed in different units?

It would be Years = Months = Days

instead of

Years + months + days