I have recently started storing xml files within SQL 2005. I have a problem extracting a date of format 20-02-2007 out of the XML and storing it in a field of datetime. The database is in American format (2007-02-20) and is failing when I try and insert the date. In the past when extracting the date at .Net level and passing through to SQL Server this was never a problem. I have tried to convert the date first but still fails. Is there an easy way to get around this problem or do I need to store the date as a string?
Thanks
Danny
You could use CONVERT function in you T-SQL statements with 105 style:
declare @.dt varchar(10)
set @.dt ='20-02-2007'
select convert(datetime,@.dt,105)
--RESULT
2007-02-20 00:00:00.000
|||Yes this worked, but I had to convert to varchar before converting to datetime (cannot convert XML directly to datetime).
Thanks
Danny