tryStrToDate


2004-04-26 09:21:08 PM
delphi82
This function returns a converted smalldatetime or '01/01/1900' if non valid date string supplied.
Have substituted constants for date and format but this always fails and returns the converted default. can not figure out why the 'tryStrToDate('01-Aug-1999',dt,tf)' is failing?
Any suggestions would be appreciated.
function tform1.getDatefromString(s: string ; fmt: string):
TdateTime;
var
dt: Tdatetime;
tf: TFormatSettings;
begin
tf.ShortDateFormat := 'dd-mmm-yyyy';
if not tryStrToDate('01-Aug-1999',dt,tf) then
begin
tf.ShortDateFormat := 'dd/mm/yyyy';
dt := strtoDate('01/01/1900');
end;
getDatefromString := dt;
end;