Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Dhubbell

Member

02-06-2019 04:13 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Labels:

Does anyone know of a function that will return the correct "Week" of the year when you enter a date?

I'm referencing this website:

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

I found Labview's "Format Date/Time String" calculates week one as 00. It's not as simple as increment by one.

Anyway, is there any accurate way to repeat the correct Week Number of the Year?

Thank you,

Doug

Solved! Go to Solution.

Solution

Accepted by topic author Dhubbell

altenbach

Knight of NI

02-06-2019 04:27 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

%U: week number of the year (00–53), with the first Sunday as the first day of week one; 00 represents the first week.

So use %U and increment by one.

*(Next time be more friendly and attach a VI that does not span about 3 screens wide. You could use arrays to simplify the code dramatically. Way too much duplication currently, making testing difficult ;))*

Solution

Accepted by topic author Dhubbell

Kyle97330

Active Participant

02-06-2019 04:31 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@altenbach wrote:

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

%U: week number of the year (00–53), with the first Sunday as the first day of week one; 00 represents the first week.

So use %U and increment by one.

This works for this year, sure, but would fail on any year starting on a Sunday (2017, for instance).

02-06-2019 04:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thank you!

RavensFan

Knight of NI

02-06-2019 04:41 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@Kyle97330 wrote:

@altenbach wrote:

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

%U: week number of the year (00–53), with the first Sunday as the first day of week one; 00 represents the first week.

So use %U and increment by one.

This works for this year, sure, but would fail on any year starting on a Sunday (2017, for instance).

You're right. It seems like LabVIEW help doesn't describe this behavior. But week 1 seems to be the first FULL week of the year. So Sunday 1/1/17 starts a full week, it gets a 1 with %U format. Monday 1/1/18 starts a full week with %W format. Those years seem to have no 0 week.

Enumerating weeks of a year is a very unusual thing to do anyway. It is more so to approximate how many weeks apart 2 different dates are by adding or subtracting.

And you can argue as to whether there should ever be a week 0 or not, and what that means if it exists. If the week of year format isn't working the way you want for whatever purpose you have, then just wrap it in a subVI that modifies the results to your needs.

altenbach

Knight of NI

02-06-2019 04:45 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Here's what I had in mind.

02-06-2019 04:46 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I wasn't expecting answers so quickly, so I hacked my way around it. I ended up adding one week and one day to get the correct week. But, I'm sure it will be inaccurate at some point in time.

Wish there was an easier vi that simply took a date and gave the correct week year each and every time.

altenbach

Knight of NI

02-06-2019 04:48 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@Kyle97330 wrote:

This works for this year, sure, but would fail on any year starting on a Sunday (2017, for instance).

Fortunately, LabVIEW is a programming language and we can work around such edge issues if needed 😄

Kyle97330

Active Participant

02-06-2019 04:53 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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:

altenbach

Knight of NI

02-06-2019 04:58 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Yes, I was reading up on the ISO definition. It's complicated. 😄