INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Formula Help

Calculate Weeknumber - (ISO 8601) Weeks start on monday and week 1 is the one including January 4th by poujor
Posted: 14 Mar 04 (Edited 28 Oct 14)

The DatePart does not calculate weeknumbers correctly in some cases.
The formula DatePart('ww',cdate(2005,1,1),2,2) ought to return 53 - it returns 9363!!

local dateTimeVar InputDate:=DateToComputeWeekNumberOn;
local numbervar A;
local numbervar B;
local datevar C;
local numbervar D;

A := Weekday(InputDate);
B := Year(InputDate + ((8 - A) Mod 7) - 3);
C := cdate(B, 1, 1);
D := (Weekday(C) + 1) Mod 7 - 3;
(InputDate - C + D) \ 7 + 1

Below is the formula with comments:
local dateTimeVar InputDate:=DateToComputeWeekNumberOn;
local numbervar A;
local numbervar B;
local datevar C;
local numbervar D;

A := Weekday(InputDate); //Day of week - 1 is sunday, 2 is monday ... 7 is saturday
B := Year(InputDate + ((8 - A) Mod 7) - 3); //Calculate thursday of current week, return year of this thursday
C := cdate(B, 1, 1);//January 1st
D := (Weekday(C) + 1) Mod 7 - 3;);//Offset to monday in week 1st

(InputDate - C + D) \ 7 + 1 //The Parens is days between monday of week 1 and inputdate

Back to Business Objects: Crystal Reports 1 Formulas FAQ Index
Back to Business Objects: Crystal Reports 1 Formulas Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close