cancel
Showing results for 
Search instead for 
Did you mean: 

Week number calculations not working ...

pouljorgensen
Discoverer
0 Kudos

Why doesn the week number calculation (ISO 8601) using datepart ('ww',#date#,crMonday,crFirstFourDays) not work?

As an example do the following formula:

DatePart('ww',CDate(2005,1,1),crMonday,crFirstFourDays)

The result is 9363, quite an impressive week number

This is an issue in versions 2008, XI R2, XI, 10 and possibly previous versions too

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I have the very same problem with Crystal XI R2.

Previously, with Crystal 8.5, this worked perfectly.

Is there a fix for this problem?

For me, this problem is very annoying, I have made a lot of financial reports that report per week.

These do not work properly right now.

Former Member
0 Kudos

I found the way:

iif(datepart("ww",#2005-01-01#,crMonday,crFirstFourDays)>54,datepart("ww",#2005-01-01#-4,crMonday,crFirstFourDays),

datepart("ww",#2005-01-01#,crMonday,crFirstFourDays))

0 Kudos

Searching notes I found the solution:

Former Member
0 Kudos

Hi Poul,

Do you want to calculate the weeknumber of a particular date? If so please try datepart('ww',CDate(2005,1,1)).

If not could you please explain me what you are trying to calculate and what output you are expecting?

Regards,

Raghavendra

pouljorgensen
Discoverer
0 Kudos

Hi Raghavendra

No I want to be able to calculate week number according to the week numbering definition from ISO 8601 - have a look at [http://en.wikipedia.org/wiki/ISO_week_date|http://en.wikipedia.org/wiki/ISO_week_date]

If you want to use datepart ('ww, ... to solve this,

you have to specify crMonday as third argument and crFirstFourDays as argument number 4 to tell datepart that weeks starts on mondays and week #1 is the one with the first 4 days of the year.

Doing this makes my example date used with datepart returns the week number 9363!!

The DatePart('ww',CDate(2005,1,1),crMonday,crFirstFourDays) is supposed to return 53!!

Weeknumbers are supposed to be between 1 and 52 or 53 depending of the year.

Be aware weeks number 1, 52 and 53 very often contains days from 2 consequtive years, when defined according to ISO 8691.

Your suggestion does not take into account the fact Weeks start on mondays and january 1st is not always the first day of week 1.

It returns week number 1

In fact it seems every day in the start of a year with weeknumber starting in the previous year gets the weeknumber calculated wrong.

Regards,

Poul

Do you want to calculate the weeknumber of a particular date? If so please try datepart('ww',CDate(2005,1,1)).

If not could you please explain me what you are trying to calculate and what output you are expecting?

Regards,

Raghavendra