How can I make correct formula for Age diff in Google sheet? [duplicate]
Asked Answered
D

2

0

So, I wanted to claculate age from user birthdate to current date in Google sheet in my expected format. I tried few formula's from some sources, but it is just not happening.

Can anyone please guide me?

For reference and test purpose, I'm attaching one Google sheet public link. No worries if email address will be shown in Googe sheet.

Link: https://docs.google.com/spreadsheets/d/1jRlr6A3YRJIo1Ah1TSlRsDcLEDV_2BJ8YaBRS3YVC6Q/edit#gid=0

Demography answered 20/11, 2022 at 8:51 Comment(0)
F
1

Assume birthday date is placed in range 'A2'.

Current age:

=DATEDIF(A2,TODAY(),"Y")&" year(s) "&DATEDIF(A2,TODAY(),"YM")&" month(s) "&DATEDIF(A2,TODAY(),"MD")&" day(s)"

Finis answered 20/11, 2022 at 9:38 Comment(0)
V
0

you could use:

=INDEX(JOIN(" ",DATEDIF(A2, NOW(), 
 {"Y", "YM", "MD"})&{" year(s)", " month(s)", " day(s)"}))

but to make it "smart" (not show null values and use plural only when needed) try:

=INDEX(JOIN(" ", LAMBDA(a, LAMBDA(x, IF(x=0,,IF(x>1, x&a&"s", x&a)))
 (DATEDIF(A2, NOW(), {"Y", "YM", "MD"})))({" year", " month", " day"})))

and for array it would be:

=INDEX(IF(ISDATE_STRICT(A2:A), TRIM(FLATTEN(QUERY(TRANSPOSE(
 IFERROR(LAMBDA(a, LAMBDA(x, IF(x=0,,IF(x>1, x&a&"s", x&a)))
 (DATEDIF(A2:A, NOW(), {"Y", "YM", "MD"})))({" year", " month", " day"}))),,9^9))), ))

enter image description here

Vaporous answered 20/11, 2022 at 12:34 Comment(2)
Hi, Thanks for the answer, but I think the another one answer is feels more easy and exact.Demography
I'll give you that this nicely handles plural, but I feel my approach is easier and more exact (with a breakdown explanation): https://mcmap.net/q/139000/-difference-between-two-dates-expressed-as-years-months-days-in-one-column-duplicateIte

© 2022 - 2024 — McMap. All rights reserved.