SQLTeam.com | Weblogs | Forums

Need help to adjust date format


I've T-SQL as follow,

sdeclare @t1 table (crtDte date);

insert into @t1 values('17/06/2013') /*Actual Date is 17 Jun 2013*/
insert into @t1 values('13/11/2013') /*Actual Date is 13 Nov 2013*/
insert into @t1 values('09/12/2014') /*Actual Date is 09 Dec 2014*/

As a result - This is an error,

Msg 241, Level 16, State 1, Line 5
Conversion failed when converting date and/or time from character string.

Please help me to adjust my format dd/mm/yyyy to yyyy-mm-dd. Then, I can insert successfully


change to use YYYYMMDD and it will be fine

insert into @t1 values('20130617')


How to transform?

All data in text file is dd/mm/yyyy. For the time being, my date time for this is nvarchar(50). I failed to change data type to date

convert (date, date_from_text_file, 103)


It's work. Thanks