我正在开发一个连接数据库的Web服务,并以字符串格式返回数据,但是当有日期时我发现了一个问题。
这是我的代码。 我只需要这个检查,因为剩下的代码可以工作..
Dim recordSet As Odbc.OdbcDataReader
'recordSet execution
Dim dataFormat As String
dataFormat = "YYYY-MM-DD"
While recordSet.Read()
For i = 0 To count
'Below the part of code i can't find a solution
If TypeOf (recordSet(i)) Is TimeSpan Then
'This is only a time like 09:12:52
ElseIf TypeOf (recordSet(i)) Is Date Then
If Format(recordSet(i)).ToString = dataFormat Then
'This is just a date like 2018-10-11
Else
'This is a timestamp like 2019-03-12 10:00:52
End If
End If
'End part
Next i
End While
问题在于它是"日期字段"转,vb.net自动在12:00:00 AM设置它,结果是时间戳,但在DB中我确定它是一个日期类型:
"timestamp" timestamp(6) NOT NULL,
"time" time(6),
"date" date