Forum Discussion
Riyaz Khan
Aug 06, 2017Copper Contributor
IF condition on DATEDIF value
Dear Friends,
Please help me out for the below issue. I have a DATEDIF value, and on which the IF condition is not working. But if I change the DATEDIF value to numeric mannually then the IF function is working.
DATEDIF value:
=DATEDIF(D3,TODAY(),"Y")&"."&DATEDIF(D3,TODAY(),"YM")&"."&DATEDIF(D3,TODAY(),"MD")
The above formula gives me exact age (year.month.days) of a Sheep/Goat based on its given birth date. As if DoB is 05-August-2015 then the arrival value would be 2.0.1 (y.m.d). Here D3 is DoB.
Here I'm trying to make another formula which shall gives me some factors for decision making. Read C3 as DATEDIF value".
=IF(AND(C3>=0.1,C3<=0.7),"Lamb",IF(AND(C3>=0.7,C3<=0.9),"Gestation Period",IF(AND(C3>=0.9,C3<=1),"Gestation Check",IF(AND(C3>=1,C3<=1.5),"Notion",IF(AND(C3>=1.5),"Sale")))))
I'm getting answer as 'Sale'. But I need all the factors based on age.
Thank you.
Riyaz,
I would solve it this way.
=LOOKUP(DATEDIF(D3,TODAY(),"M"),$H$1:$H$5,$I$1:$I$5)
- Detlef_LewinSilver Contributor
Riyaz,
I would solve it this way.
=LOOKUP(DATEDIF(D3,TODAY(),"M"),$H$1:$H$5,$I$1:$I$5)
- Riyaz KhanCopper Contributor
- Thank you Lewin...
Hi Riyaz,
You compare text value which is returned by first formula with some numbers. In logical operations any text is aways "bigger" than any numbers, e.g =("0" > 1) returns TRUE.
You need to change your logic, use numbers for the age or make conversion in second one.
- Riyaz KhanCopper Contributor
Thank you Sergei....