I am converting DB2 stored procedures to SQL Server. One of the common issue is that DB2 use a time date format timestamp
very commonly, for which the closest SQL Server equivalent appears to be datetime2
.
What is an easy way to convert DB2 timestamp
to datetime2
?
I found this question but there was not any answer.
DB2 timestamp
is very similar to SQL Server datetime2
, except a hyphen and using periods instead of colons.
You can use stuff()
to change those characters and then convert()
to datetime2
.
Examples:
declare @DB2_timpstamp varchar(30)
declare @SQL_datetime2 datetime2
set @DB2_timpstamp = '2019-02-02-11.22.33.456789'
set @SQL_datetime2 = try_convert(datetime2, stuff(stuff(stuff(@DB2_timpstamp, 17, 1, ':'), 14, 1, ':'), 11, 1, ' '))
select @SQL_datetime2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.