5
votes

I imported my Excel spreadsheet to Google and have just one error in the formula that I cannot figure out. I'm looking to calculate an anniversary date/years of service from the start date (D2) and of course today's date, using:

=DATEDIF(D2,TODAY(),"y")&" years "&DATEDIF(D2,TODAY(),"ym")&" months"

Google is giving me the error "unknown function name DATEDIF".

Does anyone know how to make this work in Google Docs?

2

2 Answers

4
votes

datedif is undocumented even in Excel,, just use plain formula in both applications:

=TODAY()-D2

in Excel you can use custom number format: yy" years "mm" months", to get the right format in Google Docs use this formula:

=text(today()-D2, "yy' years 'mm' months'")

P.S.: excel equivalent of this formula is =TEXT(TODAY()-D2, "yy"" years ""mm"" months""")

2
votes

If you still use the old Google Docs like I do, you can use these formulas instead as equivalent

DDd =DATEDIF($A2;$B2;"d") =INT($B2-$A2)
DDm =DATEDIF($A2;$B2;"m") =12*(YEAR($B2)-YEAR($A2))+MONTH($B2)-MONTH($A2)-(DAY($B2)<DAY($A2))
DDy =DATEDIF($A2;$B2;"y") =YEAR($B2)-YEAR($A2)-IF(MONTH($A2)>MONTH($B2);1;IF(MONTH($A2)=MONTH($B2);DAY($A2)>DAY($B2);0))

Source https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=8791#p42479