Date logic in Excel 2013 -


the following formula works date combinations:

=if(int(b2)=int(now()),"today",if(days(now(),b2)>365,if(days(now(),b2)/365.25>1,year(now())-year(b2),0)&" years, ","")&if(if(month(now())-month(b2)<0,month(now())-(month(b2)-11),if(days(now(),b2)<28,0,month(now())-month(b2)))=0,"",if(month(now())-month(b2)<0,month(now())-(month(b2)-11),if(days(now(),b2)<28,0,month(now())-month(b2)))&" months , ")&if(day(now())-day(b2)<0,vlookup(month(b2),{1,31;2,28;3,31;4,30;5,31;6,30;7,31;8,31;9,30;10,31;11,30;12,31},2)-day(b2)+day(now()),day(now())-day(b2))&" days") 

except if b2 16/02/2015 15:19:00 , now() 08/02/2016 14:54 result 20 days should 11 months , 30 days. i'm struggling find hole in logic.

your function appears using julian year length, rather more complicated gregorian one. that's 1 reason why function's robustness questionable.

fortunately, excel has built-in function datedif can use. but, reason, it's hidden function! (i have absolutely no clue why).

if a1 , a2 contain 2 dates, use

=datedif(a1,a2,"y") & " years, " & datedif(a1,a2,"ym") & " months, " & datedif(a1,a2,"md") & " days"

a1 must earlier a2.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -