LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Week Number of the Year

Solved!
Go to solution

Here is something simple that will allow anyone to set whatever they like for what day defines first week of year. Maybe it is overly complicated, maybe not.

I also left in the testability component so that if someone wants, for example, the first Wednesday as week one, they can back test it.

I needed this for much the same reasons. I didn't like the answers provided because I don't do .NET. I needed this for a labeling program that I wanted to auto-populate current year/week for manufacturing purposes.

0 Kudos
Message 21 of 28
(1,914 Views)

Hi Eric,

 

your VI has some problems:

  • because of that case structure based on abbreviated English weekday names it does not work in large parts of the world…
  • some constructs are Rube-Goldberg like the string formatting at the end: use FormatIntoString with %02d to get a two-digit number with leading zero. %y will always give a two-digit number, no need to check for leading zero.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 22 of 28
(1,897 Views)

Fair enough. I apologize that I let my American show by being oblivious that there are others in the world that may not use English as a primary language. (as this is just text, please note that this is a sincere comment, not being a jerk).

 

Here is a modified version of the same thing. I agree that I got a bit overzealous with making sure that I had a 2 digit year. I knew that, too, I was just doing it for the week and spaced out for a minute. Here is an updated version.

 

Sorry, had to edit a few times. First time it didn't add file. Second time, realized that the math changed from Sunday being a 0 value, as I had originally used, to Sunday being a 1, as LV uses in the Time Cluster.

 

I don't know how Goldberg-ian this solution is, it can probably be done better, but I found it simple and fairly clean compared to what I was seeing. However, I am not overly concerned about execution speed, or dealing with or integrating into a large, complicated project. If there is a better way of doing it, which I am almost certain that there is, I'm not offended if this is not the solution to use.

0 Kudos
Message 23 of 28
(1,880 Views)

Rube Goldberg: https://en.wikipedia.org/wiki/Rube_Goldberg

"Goldberg is best known for his popular cartoons depicting complicated gadgets performing simple tasks in indirect, convoluted ways."

 

So, unnecessarily complex code. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 24 of 28
(1,867 Views)

Yes, I am painfully aware of Mr. Goldberg, and the cartoons depicting his "Miraculous" inventions. It would not be the first time that my code has been compared to his style of coding, sadly.

Do you think that what I currently have is overly complicated? Why? I have been playing in LV for quite some time, but it has never been my full time occupation. As a result I have years of experience, but only months of actual knowledge. Any input is appreciated.

0 Kudos
Message 25 of 28
(1,862 Views)

This is what I did a while ago to find week number using ISO-8601. Last post of the page.

 

Ben64

0 Kudos
Message 26 of 28
(1,854 Views)

Ok. Here is something a little more cleaned up. Also, I am not doing something as convoluted as that ISO standard. That is a lot of math just to find a week of the year. I'm sure it makes perfect sense for some applications, I just have not been involved with any of those applications. I just needed to make my week codes match an online calendar that is used at our company for figuring out week of the year. The standard I was matching is that the week 1 is defined with the first Thursday of January. I think that for something simple as that, this isn't a bad application. Especially now that you have made me look at it more closely and make it more streamlined. At least I think it is. I could be wrong. I did, at least, take out the English in the code. Thank you for pointing that out. I will try and remember that next time I am posting something that I want to advertise as ubiquitous. 

 

I know that I would not have done what you did if I had to do the standard that you built. I would have hacked at it a bit more and it would have been a bit clunky and Goldberg-y. The joys of learning how to effectively program. 🙂

0 Kudos
Message 27 of 28
(1,819 Views)

Adding snippet that list all (LabVIEW) yearly week numbers with weekly start and end time ranges, adjusted for DST and selectable day of week start (defaults to Sunday at midnight).

 

List Year Week Numbers.png

Note: LabVIEW's week numbers (00-53) are sometimes offset from commercial week numbers like Calendar-365 (01-52). 

0 Kudos
Message 28 of 28
(55 Views)