TRY CONVERT

From SQL Server Wiki
Jump to navigation Jump to search
select 'select TRY_CONVERT(varchar(50), GETDATE(), 1)', TRY_CONVERT(varchar(50), GETDATE(), 1) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 2) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 2) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 3) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 3) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 4) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 4) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 5) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 5) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 6) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 6) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 7) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 7) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 8) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 8) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 9) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 9) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 10) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 10) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 11) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 11) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 12) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 12) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 13) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 13) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 14) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 14) as NewResult union 
select 'TRY_CONVERT(varchar(50), GETDATE(), 101) as NewResult', TRY_CONVERT(varchar(50), GETDATE(), 101) as NewResult
query Result
select TRY_CONVERT(varchar(50), GETDATE(), 1) 09/30/18
TRY_CONVERT(varchar(50), GETDATE(), 10) as NewResult 09-30-18
TRY_CONVERT(varchar(50), GETDATE(), 101) as NewResult 09/30/2018
TRY_CONVERT(varchar(50), GETDATE(), 11) as NewResult 18/09/30
TRY_CONVERT(varchar(50), GETDATE(), 12) as NewResult 180930
TRY_CONVERT(varchar(50), GETDATE(), 13) as NewResult 30 Sep 2018 16:42:12:267
TRY_CONVERT(varchar(50), GETDATE(), 14) as NewResult 16:42:12:267
TRY_CONVERT(varchar(50), GETDATE(), 2) as NewResult 18.09.30
TRY_CONVERT(varchar(50), GETDATE(), 3) as NewResult 30/09/18
TRY_CONVERT(varchar(50), GETDATE(), 4) as NewResult 30.09.18
TRY_CONVERT(varchar(50), GETDATE(), 5) as NewResult 30-09-18
TRY_CONVERT(varchar(50), GETDATE(), 6) as NewResult 30 Sep 18
TRY_CONVERT(varchar(50), GETDATE(), 7) as NewResult Sep 30, 18
TRY_CONVERT(varchar(50), GETDATE(), 8) as NewResult 16:42:12
TRY_CONVERT(varchar(50), GETDATE(), 9) as NewResult Sep 30 2018 4:42:12:267PM