Turning Date into seasons with Rule Engine node

Hi everyone!

Basically, I want to turn dates into seasons using the Rule Engine node. Sort of like this:

$Date$ >= “2017-12-01” AND $Date$ < “2017-02-28” => “Winter”
$Date$ >= “2017-03-01” AND $Date$ < “2017-05-31” => “Spring”
$Date$ >= “2017-06-01” AND $Date$ < “2017-08-31” => “Summer”
$Date$ >= “2017-09-01” AND $Date$ < “2017-11-31” => “Autumn”

I also tried this, but to avail:

$Date$ >= “2017-12-01” AND $Date$ < “2017-02-28” => “Winter”
$Date$ >= “2017-03-01” AND $Date$ < “2017-05-31” => “Spring”
$Date$ >= “2017-06-01” AND $Date$ < “2017-08-31” => “Summer”
TRUE => 'Autumn"

I already turned string into date-item format. However, this doesn’t seem to work, as it only returns “Autumn” and “Summer”, but “?” for the rest. I can’t seem to find the problem, so if any of you could me, I would highly appreciate it! Thank you!

Hi @morocuca, and welcome to the KNIME Forum

The rules are correct. But I think you did not use the right “quotes”. See this workflow seasons.knwf (12.4 KB)
gr. Hans

3 Likes

if the data is coming out of a database… you might consider a more generalized approach which works regardless of year…

case 
when month(date_var) in(12,1,2) then "Winter"
when month(date_var) in(3,4,5) then "Spring"
when month(date_var) in(6,7,8) then "Summer"
else "Autumn"
end as Season

Burke

3 Likes

Perfect! Thank you so much to both @HansS & @bve :slight_smile:

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.