Jun 01 2019 04:35 AM
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?
Jun 01 2019 05:28 AM
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)
Jun 03 2019 01:51 AM
@Sergei Baklan Thanks for that reply.
Is there any function in VBA which equivalent to DatedIf function?
Jun 03 2019 03:04 PM
@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.
Jun 01 2019 05:28 AM
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)