-1
我试图将不同的日期格式转换为适当的SQL DateTime格式,并且出现错误。立即使用()为国外
我有一个客户端的机器,是建立与下列日期格式,“DD-MM-YYYY”(本地化是印度)
当内VB.Net NOW()使用它分析的月份和日子向后。我试过下面的代码,但得到转换错误。
Dim Month As String = Nothing
Dim Year As String = Nothing
Dim Day As String = Nothing
Dim Hour As String = Nothing
Dim Minute As String = Nothing
Dim Second As String = Nothing
Dim strDate As String = Nothing
Dim Date_to_SQL_DateTime As Date
Month = DatePart(DateInterval.Month, Now()).ToString
Year = DatePart(DateInterval.Year, Now())
Day = DatePart(DateInterval.Day, Now())
Hour = DatePart(DateInterval.Hour, Now())
Minute = DatePart(DateInterval.Minute, Now())
Second = DatePart(DateInterval.Second, Now())
strDate = Month & “/” & Day & “/” & Year & “ “ & Hour & “:” & Minute & “:” & Second
Date_to_SQL_DateTime = Date.ParseExact(strDate, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture)
strDate返回
1/24/2017 23:17
错误我收到是
String was not recognized as a valid Datetime
您可以使用GetDate()来替代,还是仅将日期作为Date参数传递? –
@AndrewMortimer嗯,这真的打开了另一罐蠕虫......并进入使用UTC时间与用户特定的偏移量。我宁愿将时间存储在数据库中,因为日期时间和特定于当前时间。这是一个很好的想法,我需要做的事情.. –
你可以显示你的插入语句吗? –