View Single Post
  #3  
Old 02-21-2002, 12:03 AM
Ted On The NeT Ted On The NeT is offline
Senior Member
 
Join Date: Apr 2001
Posts: 2,182
Default The code ->

Here's the code Tomy... if we (you? hehe..) solve the code problem, we'll have a great function )

function date2Week(aDate: String): Integer;
var
JanuaryFirst: TDateTime;
DayNumber: Word;
FirstDayOfYear: Word;
aYear, aMonth, aDay: word;
begin
try
decodedate(StrToDate(aDate), aYear, aMonth, aDay);
except
result := -1;
exit;
end;
JanuaryFirst := EncodeDate(aYear,1,1);
FirstDayOfYear := DayOfWeek(JanuaryFirst);
// I'VE KINDA MESSED UP THE CODE FROM HERE ON. I'VE BEEN TRYING SO LONG
// I DON'T EVEN KNOW WHAT I DID, HEHE.. IT'S KINDA VAGUE TO ME :-)

DayNumber := Integer(Round(StrToDate(aDate) - JanuaryFirst));
DayNumber := DayNumber + 7 - DayOfWeek(StrToDate(aDate) - 1);
if (FirstDayOfYear in [2..5]) then
inc(DayNumber, 7);
result := (Daynumber div 7);
case result of
0: if ((DayOfWeek(encodeDate(aYear - 1, 01, 01)) > 5) or
(DayOfWeek(encodeDate(aYear - 1, 12, 31)) < 5)) then
begin { -- if there is no reason for 53 weeks -- }
result := 52;
end
else
begin
result := 53;
end;
53: if ((FirstDayOfYear > 5) or
(DayOfWeek(encodeDate(aYear, 12, 31)) < 5)) then
begin
result := 1;
end;
end; // case-statement
end; // End of function date2Week



Greetz,
::TeD On The NeT::

=[ QUESTIONS ]=========================================
don't forget to accept this reply if it helped you!
================================================== =====

=[ EXTRA INFO ]========================================
Location : Netherlands (GMT +01.00)
Languages : English, Dutch, German
Age : 25
ICQ : Be smart and figure out what my UIN is...
================================================== =====
Reply With Quote