I would like to know if it is possible to calculate the number of the week from a date using today() in the calculation field.
I have tried the format-date with the %W operator, but it doesn't work.....
thanks to all of you who participate.
Regards Javier
Solved! Go to Solution.
If using the mobile app, go with format-date as shown below:
Unfortunately format-date %W is not supported in the web app. If you want this to work in the web app you will need to use a custom JS function. For example:
function ISO8601_week_no(unix_timestamp)
{
var dt = new Date(unix_timestamp);
var tdt = new Date(dt.valueOf());
var dayn = (dt.getDay() + 6) % 7;
tdt.setDate(tdt.getDate() - dayn + 3);
var firstThursday = tdt.valueOf();
tdt.setMonth(0, 1);
if (tdt.getDay() !== 4)
{
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
}
If you are not familiar with custom JS functions. Check this blog.
Attaching samples
this is misleading since arcade functions do not work in survey123
If using the mobile app, go with format-date as shown below:
Unfortunately format-date %W is not supported in the web app. If you want this to work in the web app you will need to use a custom JS function. For example:
function ISO8601_week_no(unix_timestamp)
{
var dt = new Date(unix_timestamp);
var tdt = new Date(dt.valueOf());
var dayn = (dt.getDay() + 6) % 7;
tdt.setDate(tdt.getDate() - dayn + 3);
var firstThursday = tdt.valueOf();
tdt.setMonth(0, 1);
if (tdt.getDay() !== 4)
{
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
}
If you are not familiar with custom JS functions. Check this blog.
Attaching samples
thank you for answering both of them.
Best regards Javier