Answered by:

Date Conversion Error

Question

I am running the same Delphi 2007 code on two Windows 7 machines using an SQL server database on a remote server. When I run the code one one machine it crashes on the following line: aQuery.FieldByName('curr_date').asDateTime with exception 'EConvert
Error: 2013-1-25 00:00:00.000 is not a valid date and time' but on the other machine the code runs without any issues. The 'curr_date' field is a Datetime2 datatype. I found that if I check the value of the 'curr_date' as a string (i.e. aQuery.FieldByName('curr_date').asString),
on one machine the date is formatted as '1/25/2013' and on the other machine the date is formatted as '2013-1-25 00:00:00.000'. The machine on which the date is formatted as '2013-1-25 00:00:00.000' is the machine on which the code crashes. The regional settings
in Control Panel are identical on both machines. Anyone know what the problem is?

Did you know that the only format allowed in ANSI/ISO Standard SQL is 'yyyy-mm-dd HH:MM:ss.sssssss' and you should be using it in every application irregardless of the language? You also confuse a column
and field. This is not an SQL problem; it is a data modeling problem.

Microsoft is conducting an online survey to understand your opinion of the Technet Web site. If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.