LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert week Number into Month for a a specific Year.

Solved!
Go to solution

I have week Number 44 and year is 2022.

How to convert this week Number into month??

0 Kudos
Message 1 of 11
(2,047 Views)

Hi Risuraj,

 


@Risuraj wrote:

I have week Number 44 and year is 2022.

How to convert this week Number into month??


By applying some simple math!

 

What have you tried?

Where are you stuck?

Why don't you attach your current VI?

 

Generic advice: we don't solve your homework for free…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,028 Views)

@Risuraj wrote:

I have week Number 44 and year is 2022.

How to convert this week Number into month??


This problem cannot be solved using the information given. Please refer to https://en.wikipedia.org/wiki/ISO_week_date

 

Alternatively, you could approximate the month like this: (44/52*12)+0.5. This turns out to be end of October and seems to be a decent approximation.

Message 3 of 11
(1,998 Views)

@LLindenbauer wrote:

@Risuraj wrote:

I have week Number 44 and year is 2022.

How to convert this week Number into month??


This problem cannot be solved using the information given. Please refer to https://en.wikipedia.org/wiki/ISO_week_date

 

Alternatively, you could approximate the month like this: (44/52*12)+0.5. This turns out to be end of October and seems to be a decent approximation.


I agree.  You'd think it is a trivial thing, but the definition of the number of weeks in a year is surprisingly complicated.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 11
(1,961 Views)

I once thought it would be smart to just let .NET do the heavy lifting. As it turns out, even Microsoft did not get it right the first time: https://learn.microsoft.com/en-us/archive/blogs/shawnste/iso-8601-week-of-year-format-in-microsoft-n...

0 Kudos
Message 5 of 11
(1,935 Views)

A Gregorian year is 52.1775 weeks long,

whereas a tropical year is 52.1773768865 week long.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 11
(1,914 Views)

On top of all the complexities mentioned, I'm sure a week can be in two months.

0 Kudos
Message 7 of 11
(1,859 Views)

It can.

 

The answer can be found here but it uses .NET to do the math. I've done it but I am sure you can use LabVIEW to get the answer without using .NET Constructor/Property/Invoke nodes.

0 Kudos
Message 8 of 11
(1,821 Views)

@Eric1977 wrote:

It can.

 

The answer can be found here but it uses .NET to do the math. I've done it but I am sure you can use LabVIEW to get the answer without using .NET Constructor/Property/Invoke nodes.


Well, not that much wrong with .NET...

 

The calculations get complex at CultureInfo.CurrentCulture.Calendar, there you get rules for the week numbering... Guess you could dig into that too.


Here's an untested conversion of the start:
WeekToMonth.png

Message 9 of 11
(1,794 Views)
Solution
Accepted by topic author Risuraj

 

Your code is MUCH MORE ELEGANT than mine is. 😂 But, I've used .NET to do all the work and followed the C# code in the link I provided.

 

Convert_Year_Week_2_Date.png

0 Kudos
Message 10 of 11
(1,775 Views)