# Weeknum and Year

**URL:** <https://community.glideapps.com/t/weeknum-and-year/69262>\
**Category:** Ask for Help\
**Created:** [January 5, 2024, 7:29am UTC](https://community.glideapps.com/t/weeknum-and-year/69262 "2024-01-05T07:29:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 7:29am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/1 "2024-01-05T07:29:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [January 5, 2024, 7:38am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/2 "2024-01-05T07:38:28Z")

</div>

Try this in a math column.

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

---

<div class="post-metadata">

**Author:** ![tuzin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/tuzin/32/86077_2.png) [@tuzin](https://community.glideapps.com/u/tuzin)\
**Post date:** [January 5, 2024, 8:29am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/3 "2024-01-05T08:29:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 8:37am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/4 "2024-01-05T08:37:21Z")

</div>

Thank you!  
But I want to show me somenthing like “2024-1”, is that possible?

---

<div class="post-metadata">

**Author:** ![Antonino\_Nolasco](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/antonino_nolasco/32/80601_2.png) [@Antonino\_Nolasco](https://community.glideapps.com/u/Antonino_Nolasco)\
**Post date:** [January 5, 2024, 8:50am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/5 "2024-01-05T08:50:47Z")

</div>

> [@Jeff\_Hager](#):
>
> YEAR(Date)\*10^2+WEEKNUM(date)

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.

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 9:00am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/6 "2024-01-05T09:00:14Z")

</div>

It works. Thank Youuu!

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 5, 2024, 9:10am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/7 "2024-01-05T09:10:05Z")

</div>

Or one JavaScript column:

 ![Screenshot 2024-01-05 at 4.09.49 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/1/61ad3b8bb3763b69e2a6286c119ce974ed393ae1.jpeg)

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 5, 2024, 9:30am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/8 "2024-01-05T09:30:35Z")

</div>

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

 ![Screenshot 2024-01-05 at 4.27.11 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/a/5a4948d79ebffc28f48fdd24bd8fe2ef348ddcd2.jpeg)

```auto

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.

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 9:46am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/9 "2024-01-05T09:46:55Z")

</div>

Thank youu!!!

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 10:02am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/10 "2024-01-05T10:02:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 5, 2024, 10:04am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/11 "2024-01-05T10:04:56Z")

</div>

You need only one column to make your request… not 3 😉

Oh, do you mean month instead of week?

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 10:12am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/12 "2024-01-05T10:12:54Z")

</div>

Yesss

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 5, 2024, 10:14am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/13 "2024-01-05T10:14:39Z")

</div>

![Screenshot 2024-01-05 at 5.16.38 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/b/0bbeb06a85418fd46e1af14a568873486280235a.jpeg)

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Stefania\_Oancea](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/stefania_oancea/32/60457_2.png) [@Stefania\_Oancea](https://community.glideapps.com/u/Stefania_Oancea)\
**Post date:** [January 5, 2024, 10:18am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/14 "2024-01-05T10:18:16Z")

</div>

Thank youuu!!!

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 6, 2024, 1:07am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/15 "2024-01-06T01:07:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 6, 2024, 4:38am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/16 "2024-01-06T04:38:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 6, 2024, 4:46am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/17 "2024-01-06T04:46:06Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![tuzin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/tuzin/32/86077_2.png) [@tuzin](https://community.glideapps.com/u/tuzin)\
**Post date:** [January 6, 2024, 10:16am UTC](https://community.glideapps.com/t/weeknum-and-year/69262/18 "2024-01-06T10:16:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 6, 2024, 8:12pm UTC](https://community.glideapps.com/t/weeknum-and-year/69262/19 "2024-01-06T20:12:18Z")

</div>

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

 ![Screenshot 2024-01-06 at 3.09.19 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/e/6e1e7e65bede8053af8501174accb66f6b16fffb.png) ![Screenshot 2024-01-06 at 3.09.31 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/9/d9165873cb223f946cdc80d77d5b90f12e3be477.png)

 ![Screenshot 2024-01-06 at 3.05.41 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/8/d848b2461dfed449a516b04594e7ffc37f6f83a1.png)

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. 🤪

---

<div class="post-metadata">

**Author:** ![tuzin](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/tuzin/32/86077_2.png) [@tuzin](https://community.glideapps.com/u/tuzin)\
**Post date:** [January 6, 2024, 10:43pm UTC](https://community.glideapps.com/t/weeknum-and-year/69262/20 "2024-01-06T22:43:24Z")

</div>

Your tests are interesting but the way you reply is disgusting ☹  
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.

[Next page](https://community.glideapps.com/t/weeknum-and-year/69262.md?page=2)
