procedure DateComplete
(var StrLikeDate:string;
const NowIfError:boolean = True);
var
DateStr : string;
Year, Month, Day : Word;
i, SepCount : Integer;
begin
DateStr:=StrLikeDate;
if DateStr = '' then Exit;
SepCount := 0;
for i := 1 to Length(DateStr) do begin
if not (DateStr[i] in ['0'..'9']) then begin
DateStr[i] := DateSeparator;
inc(SepCount);
end;
end;
while (DateStr <> '') and
(DateStr[Length(DateStr)]=DateSeparator) do
begin
Delete(DateStr, Length(DateStr), 1);
Dec(SepCount);
end;
DecodeDate(Now, Year, Month, Day);
if SepCount = 0 then begin
case Length(DateStr) of
0 : DateStr := DateToStr(Now);
1, 2 :
DateStr := DateStr+DateSeparator+IntToStr(Month);
4 : Insert(DateSeparator, DateStr, 3);
6, 8 : begin
Insert(DateSeparator, DateStr, 5);
Insert(DateSeparator, DateStr, 3);
end;
end; {case}
end; {if SepCount}
try
StrLikeDate := DateToStr(StrToDate(DateStr));
except
if NowIfError = true then
StrLikeDate := DateToStr(Date)
else
StrLikeDate := '';
end;{try/except}
end;
(var StrLikeDate:string;
const NowIfError:boolean = True);
var
DateStr : string;
Year, Month, Day : Word;
i, SepCount : Integer;
begin
DateStr:=StrLikeDate;
if DateStr = '' then Exit;
SepCount := 0;
for i := 1 to Length(DateStr) do begin
if not (DateStr[i] in ['0'..'9']) then begin
DateStr[i] := DateSeparator;
inc(SepCount);
end;
end;
while (DateStr <> '') and
(DateStr[Length(DateStr)]=DateSeparator) do
begin
Delete(DateStr, Length(DateStr), 1);
Dec(SepCount);
end;
DecodeDate(Now, Year, Month, Day);
if SepCount = 0 then begin
case Length(DateStr) of
0 : DateStr := DateToStr(Now);
1, 2 :
DateStr := DateStr+DateSeparator+IntToStr(Month);
4 : Insert(DateSeparator, DateStr, 3);
6, 8 : begin
Insert(DateSeparator, DateStr, 5);
Insert(DateSeparator, DateStr, 3);
end;
end; {case}
end; {if SepCount}
try
StrLikeDate := DateToStr(StrToDate(DateStr));
except
if NowIfError = true then
StrLikeDate := DateToStr(Date)
else
StrLikeDate := '';
end;{try/except}
end;