
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how to calculate the week number from a date?
Hi,
I am using the below code to calculate previous week number based on current date:
Let vPreviousWeekID = replace(weekname(today(),-1),'/','-W');
trace 'Previous WeekID = ' & $(vPreviousWeekID);
and it gives me this results:
Previous WeekID = & 2017-W15
which is incorrect and it should be: Previous WeekID = & 2017-W17
please give me a suggestion that what is wrong here?
Thanks,
Sandip Ghosh
- « Previous Replies
-
- 1
- 2
- Next Replies »


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Let vPreviousWeekID = replace(weekname(today(),-1),'/','-W');
How did you got Previous WeekID = & 2017-W15,
for me its showing Previous WeekID = & 2017-W16

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some useful tips:
- QlikView uses the ISO week number logic, not the one from MS Outlook or other applications. This means that we are now in week 17, not 18.
- Your expression, put in a text box, displays "2017-W16" which is correct.
You are talking about script code. When did you last do your reload?
More information about how QV calculates week numbers and how you can redefine this method can be found in this great HIC treatment: Redefining the Week Numbers
Best,
Peter


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also note that there is an optional timer mode argument to Today() function, with a default value.
Depending on your test scenario, you could very well get an old date of week 16 returned.
If you want to get the date at script run, use Today(1) in your script statement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
Through week() function I am getting the correct result:
Let vPreviousWeekID = Year(today(1))& '-W' & (week(today(1))-1);
Let vCurrentWeekID = Year(today(1))& '-W' & (week(today(1)));
and it gives me the below results:
Previous WeekID = 2017-W16
current week id = 2017-W17
Please let me know if I am wrong.
Thanks,
Sandip

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
Through week() function I am getting the correct result:
Let vPreviousWeekID = Year(today(1))& '-W' & (week(today(1))-1);
Let vCurrentWeekID = Year(today(1))& '-W' & (week(today(1)));
and it gives me the below results:
Previous WeekID = 2017-W16
current week id = 2017-W17
Please let me know if I am wrong.
Thanks,
Sandip

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks ok to me. Does the weekname() variant return the same values now? It really should...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May be use this?
=Replace(WeekName(Today()),'/', '-W')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You are just copying my code and just pasting it?
try it first and you will see that only W16 is coming and it is wrong.
Thanks,
Sandip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Strange, I've removed -1 from your example. When snap comes to the picture that mean We are tested. Check from your end

- « Previous Replies
-
- 1
- 2
- Next Replies »