Reputation: 4117
I have a date field stored in the format 16/08/2010 17:17
I am attempting to store this as a datetime so that I can transform it.
Problem is I am getting an out of range error when I do. How can I resolve this issue?
My Queries:
CAST(agreement_Date AS Datetime)
CONVERT(varchar,agreement_date,126)
Error:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Upvotes: 0
Views: 217
Reputation: 4084
Try CONVERT with a style of 103: http://msdn.microsoft.com/en-us/library/ms187928.aspx
SELECT CONVERT(datetime,'16/08/2010 17:17',103)
-> 2010-08-16 17:17:00.000
@Edit: had wrong style argument
Upvotes: 1
Reputation: 65147
Instead of CAST
use:
CONVERT(datetime, agreement_Date, 103)
The 103
specifies dd/mm/yy
conversion, which I think is your issue. SQL Server is looking for the month first, and that leads to an out-of-range exception.
Upvotes: 3