LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Week Number of the Year

Solved!
Go to solution

Thanks Kyle, I'm going to run with your %U +1 option and get 6 out of 7 years right.


Thanks again for all the quick replies!

 

Doug

0 Kudos
Message 11 of 28
(2,374 Views)

To be fair that was Altenbach's solution, I just pointed out that 1/7 years it would fail.

 

Schedule time in January of 2023 now to patch the program 🙂

Message 12 of 28
(2,371 Views)

Thanks, I updated both of your comments as solutions because it's important to know there are some limitations.

0 Kudos
Message 13 of 28
(2,367 Views)

@Kyle97330 wrote:

The ISO 8601 standard for weeks states that “week 1” is the first week of the year with a Thursday in it.  Not sure if that's exactly what you want, but it would be nice if LabVIEW had that as an option.

 

If you are willing to use .NET there's an function that's more along the lines of what you need, with some configurable parameters to refine it:

get week of year snippet.png


Interesting.

I would say that LabVIEW doesn't implement that defintion.

 

Format Codes for the Time Format String

<%U> week number of the year (00–53), with the first Sunday as the first day of week one; 00 represents the first week
   
<%W> week number of the year (00–53), with the first Monday as the first day of week one; 00 represents the first week

 

For %U  (week starts on Sunday)

1/1/19  (A Tuesday) yields 00 because Week 1 starts on Sunday 1/6/19

1/1/18  (A Monday) yields 00 because Week 1 starts on Sunday 1/7/19

1/1/17  (A Sunday) yields 01 because Week 1 starts on Sunday 1/1/19

 

By the ISO 8601 standard, all 3 of those would be week 1 since they are all in the same week with a Thursday.  (Friday 1/1/xx and Saturday 1/1/xx would not be.)

Message 14 of 28
(2,359 Views)

Wow!

 

Makes you wonder how come it's so easy for websites to pull the Week of the year.  There must be a PHP function or something that helps pull the week so easily.

<?php
$ddate = "2012-10-18";
$date = new DateTime($ddate);
$week = $date->format("W");
echo "Weeknummer: $week";

 

https://www.timeanddate.com/date/weeknumber.html

 

0 Kudos
Message 15 of 28
(2,357 Views)

@Kyle97330 wrote:

The ISO 8601 standard for weeks states that “week 1” is the first week of the year with a Thursday in it.  Not sure if that's exactly what you want, but it would be nice if LabVIEW had that as an option.

 


I'm sure there exist definitions for this somewhere, that involve every possible weekday as being the first week of the year. ISO basically just assumes that the first week in a year is the first week that has at least four days, considering Monday to be the starting point for a week. This leaves out areas on the globe that consider the week to start on Sunday!. But all of these are basically as arbitrary as any other definition.

 

Unfortunately ISO isn't a standard officially sanctioned outside of the EU for most things, although it gets more and more considered as a valid recommendation even in the former "empire" areas. But the standards in programming come from the second half of last century when ISO was often seen as just a bunch of creators of difficult and mostly useless standards. Smiley Very Happy

Rolf Kalbermatter
My Blog
Message 16 of 28
(2,339 Views)

@rolfk wrote:

@Kyle97330 wrote:

The ISO 8601 standard for weeks states that “week 1” is the first week of the year with a Thursday in it.  Not sure if that's exactly what you want, but it would be nice if LabVIEW had that as an option.


ISO basically just assumes that the first week in a year is the first week that has at least four days, considering Monday to be the starting point for a week.

I've only heard the "first week with four days" definition, but that equates to there being a Thursday, I like that wording. 🙂

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 17 of 28
(2,316 Views)

 


@Yamaeda wrote:

I've only heard the "first week with four days" definition, but that equates to there being a Thursday, I like that wording. 🙂

/Y


There are several mutually equivalent and compatible descriptions of "week 01" as the ISO spec defines:

  • The week with the year's first Thursday in it (my favorite, obviously)
  • The week with January 4th in it
  • The first week with the majority (four or more) of its days in the starting year
  • The week starting with the Monday in the period December 29th-January 4th

A sufficiently creative person could come up with a few more, probably.

Message 18 of 28
(2,295 Views)

Hello,

It would be possible to have the VI with the .NET Calendar getWeekOfYear converted to Labview 2017 ?

Thanks for who can help.

 

0 Kudos
Message 19 of 28
(2,223 Views)

Sorry for sharing for any years not valid code. Here is the new one.

Condition: First week of year must have 4 days at least to mark them as 1, otherwise 0 (thu, fri, sat, sun for %W and wed, thu, fri, sat for %U).

Repaired: Missing Pad using zero when formatting week number back to string.time_repair_format_week_of_year_1.png

time_repair_format_week_of_year_2.png

 

time_repair_format_week_of_year_3.png

 

0 Kudos
Message 20 of 28
(2,078 Views)