Jan 06, 2022 07:27 AM
I wanted the Weeknum of an end date field. The week number of those records that have 12/31/2021 is 1 instead of the last number of the year. How can I turn that into 52. I was trying to do a formula like this IF({End Date} = ‘12/31/2021’, “52” , WEEKNUM({End Date})) but it wasn’t working. I am new to formulas so if you can give me guidance I would appreciate it.
Jan 06, 2022 11:29 AM
If {End Date}
outputs a valid date, then its value will likely not be "12/31/2021"
since dates are stored in UNIX timestamps. A more reliable solution would be something like IF(IS_SAME({End Date}, "12/31/2021", "day"), ...)
.
In any event, what you really should do is use DATETIME_FORMAT() to specify you want the ISO week of the year:
IF({End Date}, DATETIME_FORMAT({End Date}, "W"))
For reference, using a lower case "w"
would output a 1, same as the WEEKNUM()
function.
Jan 09, 2022 07:41 AM
Thank you so much @Kamille_Parks!
Jan 09, 2022 11:25 AM
In Airtable, weeks start on Sunday. I don’t know where you’re from, but in Europe it starts on Monday, so that to can be the reason why the week number is wrong. Is this is the case, you can also use:
WEEKNUM({end date}, "Monday"
)