我一直在寻找如何转换的答案:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: debezium-connect-source
spec:
selector:
matchLabels:
app: debezium-connect-source
replicas: 1
template:
metadata:
labels:
app: debezium-connect-source
spec:
terminationGracePeriodSeconds: 30
containers:
- name: debezium-connect-source
image: debezium/connect
env:
- name: BOOTSTRAP_SERVERS
value: kafka-service:9092
- name: GROUP_ID
value: "1"
- name: CONFIG_STORAGE_TOPIC
value: debezium-connect-source_config
- name: OFFSET_STORAGE_TOPIC
value: debezium-connect-source_offset
ports:
- containerPort: 8083
name: dm-c-source
至$ kubectl get pods
Unable to connect to the server: net/http: TLS handshake timeout
我认为07-DEC-18 01.00.54.984000 PM
的时间是13小时0分54秒
我尝试用112进行转换,但是我仍然找不到如何转换或转换的方法。
答案 0 :(得分:2)
以下是一种单独转换日期和时间部分,然后使用DATEADD
合并结果的方法。假定实际时间精度不大于毫秒。请注意,您需要使用datetime2
而不是datetime
以避免舍入为1/300毫秒。
DECLARE @DateTimeString varchar(30) = '07-DEC-18 01.00.54.984000 PM';
SELECT DATEADD(
millisecond
, DATEDIFF(millisecond, '', CAST(REPLACE(SUBSTRING(@DateTimeString, 11, 8), '.', ':') + RIGHT(@DateTimeString, 10) AS time))
, CAST(LEFT(@DateTimeString, 9) AS datetime2)
);
答案 1 :(得分:1)
这会将您的值转换为应为datetime2(6)
的数据类型。日期和时间数据类型没有格式,如果您以特定格式存储它们,那是错误的做法(因为这意味着您将值存储为varchar
)。
DECLARE @YourDate varchar(30) = '07-DEC-18 01.00.54.984000 PM';
SELECT V.YD,
TRY_CONVERT(datetime2(6),F.FormatedYD,106)
FROM (VALUES(@YourDate)) V(YD)
CROSS APPLY (VALUES(STUFF(STUFF(V.YD,13,1,':'),16,1,':'))) F(FormatedYD);
如果这是一个表,那么我将通过执行以下操作来修复您实际的列数据类型:
UPDATE YT
SET YourDateColumn = CONVERT(varchar(30),TRY_CONVERT(datetime2(6),F.FormatedYD,106),126)
FROM YourTable YT
CROSS APPLY (VALUES(STUFF(STUFF(YT.YourDateColumn,13,1,':'),16,1,':'))) F(FormatedYD);
ALTER TABLE YourTable ALTER COLUMN YourDateColumn datetime2(6);