VarToStr different formatting of dates

Hi all

I have a SQL date field that’s in a variant and when I do VarToStr on my PC I get dd/mm/yyyy but on a customers PC (Both of us have the exact same Windows short and long date formats) it’s converted to dd-mm-yyyy.

Is there something else on a PC that controls date formats?

Thanks in advance

Richard

You could assign the var to a TDateTime var and then use the FormatDateTime to have it appear in any way that you want it to, independent of windows settings.

Thanks for the suggestion.

I over simplified what I assumed was the issue that’s now been fixed.

Code was
case fColDataType of
sdtDATE: begin
Result := QuotedStr(FormatDateTime(‘yyyymmdd’, fColValue));
end;

Fixed code is:
case fColDataType of
sdtDATE: begin
Result := QuotedStr(FormatDateTime(‘yyyymmdd’,
VarToDateTime(fColValue)));
end;

I fixed it by doing VarToDateTime(fColValue)

Error message that was being captured was “Could not convert variant of type
(UnicodeString) into type (Double)”.

I was wondering if differing version of the dll’s associated with getting
the data from a MS SQL server would have any bearing on it?

Just weird that even when we had the same Windows date formats that and I
was using VarToStr in debug logs that I was getting dd/mm/yyyy vs client
getting dd-mm-yyyy when processing the exact same data record.

Kind regards

Richard Moore

Hi Richard

Could the software be using the default date format for the machine (short or long)?

The url https://www.howtogeek.com/247141/how-to-change-the-format-of-dates-and-times-in-windows/ may help you to check each machine.

Regards
Graeme

Hi Graeme

That’s what I assumed but the clients date separator was / and VarToStr resulted in dd-mm-yyyy

image001.png