简体   繁体   中英

Confused on Excel DATEDIF “YD” Option

I am having trouble understanding the below results:

=DATEDIF(DATE(2003,9,29),DATE(2013,8,28),"YD")

returns 334

whereas

=DATEDIF(DATE(2012,9,29),DATE(2013,8,28),"D")

and

=DATE(2013,8,28)-DATE(2012,9,29)

returns 333 and is what I ultimately expect to get.

Why does the first formula return 334?

Thank you!

EDIT: Ultimately, what I want to achieve is to take in 2 dates and return the number of full years (so /365 doesn't work due to leap) + the remainder days to be divided by 365.

I thought of using

=DATEDIF(date1,date2,"Y")+DATEDIF(date1,date2,"YD")/365

but cases similar to the above throws it off. I could do a long-winded one, but was wondering about causes this.

怎么样

=DATEDIF(DATE(2003,9,29),DATE(2013,8,28),"y")+(DATE(2013,8,28)-EDATE(DATE(2003,9,29),12*DATEDIF(DATE(2003,9,29),DATE(2013,8,28),"y")))/365

Chip Pearson explains why that happens here - scroll down the page to near the end, under "DATEDIF And Leap Years"

I recommend nutsch 's solution to your problem but you might also want to look at YEARFRAC function to get fractional years - I don't seem to be able to get the exact same results as with nutsch's formula but this will give you something close

=YEARFRAC(A2,B2,3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM