Hi,

Threw the following code together. Took a little different approach then
others presented by starting at the end of the month and working backwards.
I tested it for 2004, 2005 and 2006 and it looks ok. (Used D7).


uses
    DateUtils;

function CalcSundaysInMonth(AMonth, AYear: Integer): Integer;
var
  iLastDayOfMonth: Integer;
  iDayInMonth: Integer;
begin
  // Calc last day # in month
  iDayInMonth := DaysInAMonth(AYear, AMonth);

  // Get last day (Mon, Tue...) in month
  iLastDayOfMonth := DayOfTheWeek(EncodeDate(AYear, AMonth, iDayInMonth));

  // Offset to previous Sunday & divide by # of days/week
  Result := ((iDayInMonth-(iLastDayOfMonth mod 7)) div 7)+1;
end;

Scott Kellish
[EMAIL PROTECTED]



----- Original Message ----- 
From: "Agustin Galloso Viera" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Wednesday, May 18, 2005 10:52 AM
Subject: Calculating Sundays ...


> Hi Delphicians ...
>
> How I know how many Sundays have some month in some year ?? for example :
if
> i have May 2005 it give me 5. There are any function that resolve this,
any
> WEb about this, article, etc ??
>
> Thanks 4 all...
>
> ---
> Agustin Galloso Viera
> [EMAIL PROTECTED]
>
>
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
>


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to