Formula based on date
I am trying to RTFM...
I want to calculate a value based on a date.
If the date is before 2017 subtract 20 from Field, or if the date is between 01-07-2018 and 31-12-2019 subtract 10 from Field, otherwise subtract 5 from Field.
I'm either not so clever or the manual is confusing or the logic used isn't as logical as I thought!
5 replies
-
This bit works
if year('Date & Time') < 2017 then
'Miles Travelled' - 20
else
'Miles Travelled' - 10
end
I can't get anothe IF in there though...
-
Why doesn't this work?
if timestamp('Date & Time') < 1483228800 then
'Miles Travelled' - 22;
if timestamp('Date & Time') < 1522537200 then
'Miles Travelled' - 32
else
'Miles Travelled' - 20
end
end
(1483228800 is the unix timestamp for 01-01-2017)
Am I trying to do the impossible?
-
if condition then
calculation
else
if condition then
calculation
else
calculation
end
end
...Or you could use a switch statement.
-
Thanks. The missing 'else' dosn't help me. The two if statements fail and I end up with the final calculation.
For a record dated in 2016, the first if should find a date before 01-01-2017 in 'Date & Time' and subtract 22 from 'Miles Travelled'. It doesn't, it just moves through to the final else.
I can make
if year('Date & Time') < 2017 then
work but I can't find a month and year if I try
if yearmonth('Date & Time') < 2016/04 then
Will a switch help?!
-
Here's the answer!
My tme stamps were short. I got the stamp for 01-01-2017 from https://www.unixtimestamp.com and it returned 1483228800.
The stamps from Ninox are longer by three zeros. Once I used 1483228800000 in the condition all was well.
Phew!
Content aside
- 3 yrs agoLast active
- 5Replies
- 255Views