I am having below code which is working fine on my system as my date time format of the system is dd-mm-yyyy, but below code does not work where date time format of system is dd/mm/yyyy.
try
fmt.LongDateFormat:='dd-mm-yyyy';
fmt.DateSeparator :='-';
fmt.LongTimeFormat :='hh:nn:ss.z';
fmt.TimeSeparator :=':' ;
dateTime :=42467.51801;
strDate :=FormatDateTime('dd-mm-yyyy hh:nn:ss.z', dateTime);
time := StrToDateTime(strDate,fmt);
strDate :=FormatDateTime('dd-mm-yyyy hh:nn:ss.z', time);
ShowMessage('DateTime := ' +strDate) ;
except
on e: Exception do
ShowMessage('Exception message = '+e.Message);
end;
the same code with format dd/mm/yyyy does not work on my system. Please help me.
Your code is using
LongDateFormatandLongTimeFormat, butStrToDateTime()does not use those values.StrToDate()andStrToDateTime()useShortDateFormat(andTwoDigitYearCenturyWindow, which does not apply in this case) to parse dates.StrToTime()andStrToDateTime()use hard-coded logic to parse times. You cannot specify the order/presence of the hour/minute/second/millisecond values, you can only specify theTimeSeparator,DecimalSeparator,TimeAMString, andTimePMStringvalues.Try this instead: