How do I convert date like '31/06/2013' or '30/02/2013' of datatype varchar in SQL Server 2008 -
i have column named next_due_date
datatype varchar
, in column non-existing dates 31/06/2012
or 30/02/2013
saved. because of error message when convert date
datatype.
the conversion of varchar data type datetime data type resulted in out-of-range value.
if dates would valid (not 31st of june or 30th of february - dates don't exist!), use convert
function convert them date
:
declare @datetable table (datecolumn varchar(20)) -- **valid** dates - 30th of june, 28th of feb insert @datetable(datecolumn) values ('30/06/2012'), ('28/02/2013') -- converted date type using style #104 select datecolumn, convert(date, datecolumn, 104) @datetable
Comments
Post a Comment