If Statement between dates
I am trying to figure out a formula to give a value using the If statement but am struggling to make it work. I need something like this:
if 'datefield' >= '01 Aug 2016' and <= '31 Jul 2017' then '16/17' else 'Other' end
10 replies
-
Try this...
let startDate := date(2016, 8, 1);
let endDate := date(2017, 7, 31);
if dateField >= startDate and dateField <= endDate then
text("16 / 17")
else
text("Other")
end -
Perfect formula - I was struggling with the date format year / month / day
Thank you
-
I thought I would add my final formula if anyone else needs an example of this:
let YS14 := date(2014, 8, 1);
let YE15 := date(2015, 7, 31);
let YS15 := date(2015, 8, 1);
let YE16 := date(2016, 7, 31);
let YS16 := date(2016, 8, 1);
let YE17 := date(2017, 7, 31);
let YS17 := date(2017, 8, 1);
let YE18 := date(2018, 7, 31);
let YS18 := date(2018, 8, 1);
let YE19 := date(2019, 7, 31);
let YS19 := date(2019, 8, 1);
let YE20 := date(2020, 7, 31);
let YS20 := date(2020, 8, 1);
let YE21 := date(2021, 7, 31);if 'Learning start date' >= YS14 and 'Learning start date' <= YE15 then
text("14 / 15")
else
if 'Learning start date' >= YS15 and 'Learning start date' <= YE16 then
text("15 / 16")
else
if 'Learning start date' >= YS16 and 'Learning start date' <= YE17 then
text("16 / 17")
else
if 'Learning start date' >= YS17 and 'Learning start date' <= YE18 then
text("17 / 18")
else
if 'Learning start date' >= YS18 and 'Learning start date' <= YE19 then
text("18 / 19")
else
if 'Learning start date' >= YS19 and 'Learning start date' <= YE20 then
text("19 / 20")
else
if 'Learning start date' >= YS20 and 'Learning start date' <= YE21 then
text("20 / 21")
else
text("New Year Required")
end
end
end
end
end
end
end -
Check out “Switch Case” in the language reference
-
I just suggested it because it is well suited for what you are doing here.
-
Just trying to test this but am a little unsure how it works.
-
My bad! I was distracted when I posted that. Switch evaluates a single expression which you then check for possible results. You are testing multiple expressions. I am very sorry for the confusion!
-
Hi slowwagon,
hi Andrew,
this can also be realized with switch:
---
let YS14 := date(2014, 8, 1);
let YE15 := date(2015, 7, 31);
let YS15 := date(2015, 8, 1);
let YE16 := date(2016, 7, 31);
let YS16 := date(2016, 8, 1);
let YE17 := date(2017, 7, 31);
let YS17 := date(2017, 8, 1);
let YE18 := date(2018, 7, 31);
let YS18 := date(2018, 8, 1);
let YE19 := date(2019, 7, 31);
let YS19 := date(2019, 8, 1);
let YE20 := date(2020, 7, 31);
let YS20 := date(2020, 8, 1);
let YE21 := date(2021, 7, 31);
switch 'Learning start date' >= 0 and 'Learning start date' <= date(2050, 7, 31) do
case 'Learning start date' >= YS14 and 'Learning start date' <= YE15:
"14 / 15"
case 'Learning start date' >= YS15 and 'Learning start date' <= YE16:
"15 / 16"
case 'Learning start date' >= YS16 and 'Learning start date' <= YE17:
"16 / 17"
case 'Learning start date' >= YS17 and 'Learning start date' <= YE18:
"17 / 18"
case 'Learning start date' >= YS18 and 'Learning start date' <= YE19:
"18 / 19"
case 'Learning start date' >= YS19 and 'Learning start date' <= YE20:
"19 / 20"
case 'Learning start date' >= YS20 and 'Learning start date' <= YE21:
"20 / 21"
default:
"New Year Required"
end---
But you can also do a lot easier:
---
let myDeadline := date(year('Learning start date'), 8, 1);
let myYear := number(format(myDeadline, "YY"));
if 'Learning start date' >= myDeadline then
myYear + " / " + (myYear + 1)
else
myYear - 1 + " / " + myYear
end---
so you can calculate all years without limit
Leo
-
Thank you - that is really helpful
Andrew
-
Thank you Leo!
Content aside
- 6 yrs agoLast active
- 10Replies
- 3912Views