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.
FormatDateTime
works perfectly well with the code you've posted if you properly assign your date format toShortDateFormat
instead ofLongDateFormat
. For the date you provided, it produces07-04-2016 12:25:56.64
.