# Board index » delphi » Week Number Question....

## Week Number Question....

How do you determine if a given date is within the (1st week, 2nd week,
3rd week, 4th week) of the month?

## Re:Week Number Question....

That would depend on how you define the start of the first week in a month.
And remember, there can be more than 28 days in a month!

Marlon D. Gallego <mgall...@i-mailbox.net> skrev i en
nyhedsmeddelelse:37CE78ED.2CDA9...@i-mailbox.net...

##### Quote
> How do you determine if a given date is within the (1st week, 2nd week,
> 3rd week, 4th week) of the month?

## Re:Week Number Question....

"Marlon D. Gallego" <mgall...@i-mailbox.net> wrote:

##### Quote
>How do you determine if a given date is within the (1st week, 2nd week,
>3rd week, 4th week) of the month?

WeekOfMonth := (DayOfMonth - 1) div 7 + 1;

--
Regards,
Chris Roberts

## Re:Week Number Question....

Never done this in Delphi but have done similar in assembly/C and the route
I would go is:

In TDateTime format the integer part is the number of days, so use
EncodeDate to get the days before 1st of month, 8th of month, etc and then
if then statement for your actual test date :
actualdate:=int(ofTDateTime);
if actualDate<1st then
week:=0 //not this month
else if ActualDate<8th then
week:=1
etc. etc.

_+_+__+
If you want to work out if it is the first 'Standard' week of the month
(based on the week numbers from year start and as used by TMonthCalender
then I would suggest that you subtract #days at year start from ActualDate,
1st of month, 8th of month etc  to get number of days in this test year for
each week start and the test date.  Convert these to weeks in the year by
finding the days to first Sunday of the year (how, I don't know off hand but
you could hard code in a known Sunday a few years before any test date to
use as a reference - remember leaps!), subtract from ActualDate, 1st etc and
then divide by 7, plus 1.  Up to that first Sunday is Week1.

You can then test to see which weeknumber [1st, 8th etc] matches the test
date to get what week in year and month.

Doesn't give you code but hopefully points in the right direction.

MarkRobertson

##### Quote
Marlon D. Gallego wrote in message <37CE78ED.2CDA9...@i-mailbox.net>...
>How do you determine if a given date is within the (1st week, 2nd week,
>3rd week, 4th week) of the month?