Print Page | Close Window

Get week number for the month

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=14446
Printed Date: 02 May 2024 at 9:00am


Topic: Get week number for the month
Posted By: Elisha83
Subject: Get week number for the month
Date Posted: 22 Sep 2011 at 1:49am
Hi there,
 
I need help in retrieving week number of the month based on my transaction date. Below is the example of my expected results.
 
 
Invoice         Trans. Date         Week
IN001             03/01/2011           2
IN002             31/01/2011           6
IN003             01/02/2011           1
IN004             28/02/2011           5
IN005             06/03/2011           1
IN006             14/03/2011           3
 
 
Urgently need help in getting the right formula as I have try a lot of time but could not get the accurate output. Your help is kindly appreciated.
 
Thanks in advance... Big%20smile
 


-------------
3Lish@



Replies:
Posted By: rybad80
Date Posted: 20 Aug 2013 at 5:18am
Try this. It worked for me



shared datevar dtmTargetDate := date({PRE_CASE.START_DATE});
shared datevar dtmStartDate := date({PRE_CASE.START_DATE});
shared numbervar dtmDay := DatePart("d", dtmTargetDate);
shared numbervar dtmMonth := DatePart("m", dtmTargetDate);
shared numbervar dtmYear := DatePart("yyyy", dtmTargetDate);
shared numbervar intWeekday;
shared numbervar intAddon;
shared numbervar intWeek1;
shared numbervar intWeek2;
shared numbervar intWeek3;
shared numbervar intWeek4;
shared numbervar intWeek5;
shared numbervar intWeek6;
shared numbervar numWeek;

intWeekday := Weekday({PRE_CASE.START_DATE});
intAddon := 8 - intWeekday;

intWeek1 := intAddOn;
intWeek2 := intWeek1 + 7;
intWeek3 := intWeek2 + 7;
intWeek4 := intWeek3 + 7;
intWeek5 := intWeek4 + 7;
intWeek6 := intWeek5 + 7;

If dtmDay <= intWeek1 Then
    numWeek := 1
Else

If dtmDay <= intWeek2 Then
    numWeek := 2
Else

If dtmDay <= intWeek3 Then
    numWeek := 3
Else

If dtmDay <= intWeek4 Then
    numWeek := 4
Else

If dtmDay <= intWeek5 Then
    numWeek := 5
Else

If dtmDay <= intWeek6 Then
   numWeek := 6;

numweek;




Print Page | Close Window