SOLVED

Different results from DatedIf and DateDiff functions

Copper Contributor

I was trying to find out the difference between two dates (10-06-1985 and 01-06-2019) using these functions. DatedIf Function returned the result 33 and DateDiff function in VBA returned 34

 

I thought both functions are the same. Can anyone here tell me why this difference?

3 Replies
best response confirmed by Ajay_Anand (Copper Contributor)
Solution

@Ajay_Anand , IMHO, they have different logic.

DateDif calculates complete years, months, etc. Actually for your sample it'll be 33 years 11 months and some days, return for years is 33.

 

DateDiff checks if you over the year, month, etc.

 

For more simple example, if start date 30 Dec 2018 and end date 10 Jan 2019 when

DateDif returns 0 years (0 years 0 months 11 days)

DateDiff returns 1 year (you are over year 2018)

@Sergei Baklan Thanks for that reply.

Is there any function in VBA which equivalent to DatedIf function?

@Ajay_Anand , I don't think so. People suggest to evaluate DateDif https://stackoverflow.com/questions/35397822/datedif-function-in-vba, but I didn't play with that.

1 best response

Accepted Solutions
best response confirmed by Ajay_Anand (Copper Contributor)
Solution

@Ajay_Anand , IMHO, they have different logic.

DateDif calculates complete years, months, etc. Actually for your sample it'll be 33 years 11 months and some days, return for years is 33.

 

DateDiff checks if you over the year, month, etc.

 

For more simple example, if start date 30 Dec 2018 and end date 10 Jan 2019 when

DateDif returns 0 years (0 years 0 months 11 days)

DateDiff returns 1 year (you are over year 2018)

View solution in original post