How to find week number of a date within a month

Pls let me know how to find week of the month.

For example for the date feb 9, 2007 should return :

2 week of feb.2007 or week 2

Thx in advance!

format function for date with parameters gives week number of year. I need of month for a particular date.

Subject: How to find week number of a date within a month

Hi,

With changes above has some mistakes

Dim ctdt As New NotesDateTime(“”)

Dim ntdt As New NotesDateTime("")

Set cfdt=New NotesDateTime(Today)

thisweek1$ = Format(cfdt.DateOnly,"ww")

eval% = Day(cfdt.DateOnly)

Msgbox eval% 

fdymon$ = eval% - 1

Msgbox fdymon$



Set ntdt =New NotesDateTime(cfdt.DateOnly)

Call ntdt .AdjustDay( -fdymon$  )





thisweek2$ = Format(ntdt.DateOnly,"ww")

thisweek$ = (thisweek1$ - thisweek2$) +1

	Msgbox "The Week Number is : "+ thisweek$+"Week"

Subject: Try this

'Get the first day of the month in the given date.'Get First Saturday from that first day (Adjust date in order to get it.

'In loop, Add 7 days to it, and count, till it is greater than the given day

Set cfdt = New NotesDateTime(“02/29/2004”) 'Given day

dy% = Day(cfdt.DateOnly) 'day, which is 29

Call cfdt.AdjustDay(- dy%+1) 'Get to 1st of month(02/01/04)

wkday% = Weekday(cfdt.DateOnly) 'Gives 1 as it is Sunday

If wkday% <> 7 Then Call cfdt.AdjustDay(7-wkday%) 'Adjust the date to first saturday

curdy% = Day(cfdt.DateOnly) 'Saturday’s day in the adjusted date

sfx% = 7 'constant

'Loop from curdy to dy by incrementing curdy by 7. Count no. of increments till curdy passes dy. The count gives the week number.

Do Until curdy% >= dy%

If curdy% <= 7 Then ctr% =1

curdy% = curdy%+sfx%

If curdy% <= dy% Then ctr% = ctr%+1

If curdy% > dy% Then 

	ctr% = ctr%+1

	Exit Do

End If

Loop

If ctr% = 1 Then key$ = “st”

If ctr% = 2 Then key$ = “nd”

If ctr% = 3 Then key$ = “rd”

If ctr% > 3 Then key$ = “th”

Msgbox “The given day is in” & Cstr(ctr%) & key$ & " Week."

Result ----> The given day is in 5th Week.

Hope this helps

Subject: How to find week number of a date within a month

Code that I am using to get the week number

Dx := StatusinDate;

AYear:= @Year(@Date(Dx));

wd:=@Weekday(Dx);

mon:= @If(wd=1;2-wd-7;2-wd);

D := @Date(@Adjust ( @Date ( Dx ) ; 0 ; 0 ; mon ; 0 ; 0 ; 0 ));

FirstOfYear := @Date(@Year(D); 1; 1);

LastOfYear := @Date(@Year(D); 12; 31);

FirstDayNum := @Weekday(FirstOfYear);

LastDayNum := @Weekday(LastOfYear);

ISOFirstDayNum := @If(FirstDayNum = 1; 7; FirstDayNum - 1);

ISOLastDayNum := @If(LastDayNum = 1; 7; LastDayNum - 1);

IsFirstWeek := 7 - ISOFirstDayNum > 2;

IsLastWeek := 7 - ISOLastDayNum < 4;

ISOFirstDay := @If(IsFirstWeek;

        @Adjust(FirstOfYear; 0; 0; 1 - ISOFirstDayNum; 0; 0; 0);

        @Adjust(FirstOfYear; 0; 0; 8 - ISOFirstDayNum; 0; 0; 0));

ISOLastDay := @If(IsLastWeek;

        @Adjust(LastOfYear; 0; 0; 7 - ISOLastDayNum; 0; 0; 0);

        @Adjust(LastOfYear; 0; 0; -ISOLastDayNum; 0; 0; 0));

FirstWeekNextYear := @If(D > ISOLastDay; @Return(@Integer(1)); NULL);

LastWeekLastYear := (D - @Adjust(FirstOfYear; -1; 0; 0; 0; 0; 0))/60/60/24/7;

AdjustLastWeek := 1 - (LastWeekLastYear - @Integer(LastWeekLastYear));

@Set(“LastWeekLastYear”; LastWeekLastYear + AdjustLastWeek);

@If(D < ISOFirstDay;

@Return(@Integer(LastWeekLastYear)); NULL);

NumWeeks := (D - ISOFirstDay)/60/60/24/7;

WeekAdjust := 1 - (NumWeeks - @Integer(NumWeeks));

ISOWeekNum := NumWeeks + WeekAdjust;

Result := ISOWeekNum;

@Text(AYear)+“-” + @Right(“0” + @Text(Result);2)

Subject: an easier formula

i used the formula for years now and have just come across this one for excel (because of differences in the us and europe, where 1.1.2006 is week 52 of 2005):

=TRUNC((A1-WEEKDAY(A1;2)-DATE(YEAR(A1+4-WEEKDAY(A1;2));1;-10))/7)

this should also be possible in notes formula.

is it too good to be correct?

Subject: RE: How to find week number of a date within a month

hi, Danny

Thx a lot for providing the code

but this is same as format function in lotus script

this code provides week number within a year i.e (0-53)

what i require is the code for week number within a month

(1-5) for example 09/02/2007

gives week no:2 within feb month

Thx in advance.

Subject: RE: How to find week number of a date within a month

First get the weeknumber for 09/02/2007 with the Format function.Then get the weeknumber for 01/02/2007 with the Format function.

Week = Weeknr 09/02 - Weeknr 01/02 + 1

Subject: RE: How to find week number of a date within a month

hi, Rene

My luck ,this question was not asked for my aptitude test.

Well this seems bright and working thanks

pasting the code for your reference and if any enhancement let me know.

my code :

Today can be replaced by the particular date in question.

            Dim ctdt As New NotesDateTime("")

Dim ntdt As New NotesDateTime("")



Set cfdt=New NotesDateTime(Today)

thisweek1$ = Format(cfdt.DateOnly,"ww")

fdymon$ = thisweek1$ - 1



Set ntdt =New NotesDateTime(cfdt.DateOnly)

Call ntdt .AdjustDay( -fdymon$  )



thisweek2$ = Format(ntdt.DateOnly,"ww")

thisweek$ = thisweek1$ - thisweek1$ +1

Msgbox "The Week Number is : "+ thisweek$+“Week”

Subject: an easier formula

i used the formula for years now and have just come across this one for excel (because of differences in the us and europe, where 1.1.2006 is week 52 of 2005):

=TRUNC((A1-WEEKDAY(A1;2)-DATE(YEAR(A1+4-WEEKDAY(A1;2));1;-10))/7)

this should also be possible in notes formula.

is it too good to be correct?