0

努力为此编写代码:

数据库中的字段具有此值:1899-12-30 04:00:00.000

我希望它回到 2013-07-23 04:00:00.000

所以从数据库字段中获取时间,然后与今天的日期连接。

有人可以帮忙吗?

问候

4

1 回答 1

2

简而言之: Date.Today.Add(oldDate.TimeOfDay)

假设 SQL-Server:

Dim result As Date
Const sql = "SELECT TOP 1 DateCol FROM dbo.TableName WHERE SomeColumn=@SomeParameter;"
Using con = New SqlConnection("Your connection string")
    Using cmd = New SqlCommand(sql, con)
        cmd.Parameters.AddWithValue("@SomeParameter", yourVariable)
        con.Open()
        Using reader = cmd.ExecuteReader()
            If reader.Read() Then
                Dim oldDate = reader.GetDateTime(0)
                result = Date.Today.Add(oldDate.TimeOfDay)
            End If
        End Using
    End Using
End Using
于 2013-07-23T15:06:09.543 回答