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 :wink:

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. :crazy_face:

Your tests are interesting but the way you reply is disgusting :frowning:
What are those columns you use in your testing? It’s hard to understand from icons.
I speak about JS column from experience of looking at the results in both data editor and live apps multiple times. Again, if JS column is slower in regular use cases and is faster in purposely complicated ones — for me that means that it’s best not to prefer JS in the long run. When you build something that needs to be really reliable, you should be really cautious when you see “experimental”, which is the very name of the folder with JS column.