At the risk of a little obfuscation you could use the one-liner: Year_of_week = year(date - min(7, 7 * floor((week - 2) / 50))) ; to derive the year from the week number without needing the complex if statement.