Weeknum and Year

Hello,
Can someone tell me if it is possible to use the weeknum function and also use a formula to add the year of that week?

Try this in a math column.

`YEAR(Date)*10^2+WEEKNUM(date)`

2 Likes

Or you can use a Format Date column
Use `yyyy` to return the year
`W` to return the number of the week
and `WW` to return the padded number

I personally prefer the math column approach Jeff suggested, but sometimes you need more than just a number

Thank you!
But I want to show me somenthing like â€ś2024-1â€ť, is that possible?

You can create two Math columns, one for Year YEAR(Date) and one for Week WEEKNUM(date), then create a Template column with this:

X-Y where X is the Year column and Y the Week column.

1 Like

It works. Thank Youuu!

1 Like

Or one JavaScript column:

``````var ddd = new Date();
var onejan = new Date(ddd.getFullYear(), 0, 1);
var week = Math.ceil((((ddd.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7);

return ddd.getFullYear()+'-'+week
``````
1 Like

If you need to get a date from an existing column, use this:

``````
var ddd = new Date(p1);
var yyy = ddd.getFullYear();
var onejan = new Date(yyy, 0, 1);
var week = Math.ceil((((ddd.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7);

return yyy+'-'+week
``````

Using my solution will speed up your App two timesâ€¦ which will be helpful if you have lots of rows to compute.

1 Like

Thank youu!!!

And for month? Can you show me the code, please?

You need only one column to make your requestâ€¦ not 3

Oh, do you mean month instead of week?

Yesss

``````var ddd = new Date(p1);
var yyy = ddd.getFullYear();
var mmm = ddd.getMonth()+1;
var onejan = new Date(yyy, 0, 1);
var week = Math.ceil((((ddd.getTime() - onejan.getTime()) / 86400000) + onejan.getDay() + 1) / 7);

return yyy+'-'+mmm+'-'+week
``````
1 Like

Thank youuu!!!

1 Like

Please test the JavaScript method above in iOS to see if it works correctly. Itâ€™s a nice solution, but sometimes Safari doesnâ€™t like the Date functions for Glide.

1 Like

I have seen JS date functions fail on IOS in the past, so I try to avoid them.

The only method I feel 100% confident about is the Glide Date Math method.

3 Likes

Nopeâ€¦ Glide dates failed many times for meâ€¦ javascriptâ€¦ neverâ€¦ but the secret is, that you need to stick to java from the beginningâ€¦ meaning get all your dates from the JavaScript columnâ€¦ do all the computing in JavaScript columnsâ€¦ and convert to localeString when you need to display itâ€¦
This is absolutely necessary if you work with users from different time zones and importing/exporting data to external sources.
@Darren_Murphy, how do you think the math column dates work??? I think it is a JavaScript codeâ€¦

Javascript is the slowest column ever, itâ€™s best to avoid it if possible.
As for 2024-1, the fastest and the most reliable is math+template
Format Date is slower, but thatâ€™s one column
And JavaScript is simply the slowest, so not recommended

1 Like

@tuzin, I donâ€™t know where you are getting your informationâ€¦ LOL
JavaScript always beats the Math columnâ€¦ did you even do testing before writing your statement???

Here is my test:

Math column 114 milliseconds, JavaScript 112 milliseconds.
And if you wanna count on the reliability of the math columnâ€¦ LOL, only if the source is Glideâ€¦ otherwise, it is the same as JavaScriptâ€¦ thatâ€™s why I always use JavaScript as my calculation and format baseâ€¦ Good luck trying to export Math column results outside and relying on the calculations based on that.