I have a Delphi 2007 procedure to determine the numerical value of the first Monday in the current year. My code is as follows:
Var
WeekDay: integer;
MyDate: TDateTime;
begin
Decodedate(Date,Y,M,D);
MyDate := EncodeDate(Y,1,1);
WeekDay := DayOfWeek(MyDate);
if WeekDay = 1
then
MyDate := MyDate + 1;
If WeekDay = 2
Then
MyDate := MyDate;
If WeekDay = 3
Then
MyDate := MyDate + 6;
If WeekDay = 4
Then
MyDate := MyDate + 5;
If WeekDay = 5
Then
MyDate := MyDate + 4;
If WeekDay = 6
Then
MyDate := MyDate + 3;
if WeekDay = 7
Then
MyDate := MyDate + 2;
For 2012 January 1st My Date is 4909 and WeekDay is 2. When I iterate through the code the line MyDate := MyDate + 1; is skipped.
Why? What is causing this?
Var
WeekDay: integer;
MyDate: TDateTime;
begin
Decodedate(Date,Y,M,D);
MyDate := EncodeDate(Y,1,1);
WeekDay := DayOfWeek(MyDate);
if WeekDay = 1
then
MyDate := MyDate + 1;
If WeekDay = 2
Then
MyDate := MyDate;
If WeekDay = 3
Then
MyDate := MyDate + 6;
If WeekDay = 4
Then
MyDate := MyDate + 5;
If WeekDay = 5
Then
MyDate := MyDate + 4;
If WeekDay = 6
Then
MyDate := MyDate + 3;
if WeekDay = 7
Then
MyDate := MyDate + 2;
For 2012 January 1st My Date is 4909 and WeekDay is 2. When I iterate through the code the line MyDate := MyDate + 1; is skipped.
Why? What is causing this?