[英]Convert a string to datetime2
Iam using an application that gets data through a communication protocol , and among data i get is dates and i managed to form a string date out of that in this form : 我使用的应用程序通过通信协议获取数据,并且我获取的数据中有日期,而且我设法以这种形式形成了一个字符串日期:
"dd/MM/yyyy HH:mm:ss.mmm"
I want to insert it in the database : 我想将其插入数据库中:
updateEvent_list = "INSERT INTO Events_List (date, Object,Event,IOA,ASDU) VALUES(@date, @event_object, @Event, @IOA, @ASDU)";
The date column
is of datetime2
type . date column
datetime2
类型。
Question is : how can i convert the string i get into datetime2
??? 问题是:如何将获取的字符串转换为
datetime2
?
EDIT : 编辑:
In fact i have two types of dates to insert : 1) Frames that come with time tag : the ones that i convert their dates to string. 实际上,我要插入两种类型的日期:1)带有时间标签的帧:我将其日期转换为字符串的帧。 2) Frames that come without timetag : Iam using
DateTime date =DateTime.UtcNow
2)没有时间戳的帧:使用
DateTime date =DateTime.UtcNow
Iam
Each of these work perfectly when they implemented independantly 当它们独立实施时,它们中的每一个都能完美地工作
Is there any solution that permits using both in the same program ?? 是否有允许在同一程序中同时使用两者的解决方案?
您可以使用CAST
:
"INSERT INTO Events_List (date, Object,Event,IOA,ASDU) VALUES(CAST(@date as DATETIME2), @event_object, @Event, @IOA, @ASDU)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.