如何删除时间?

时间:2013-08-13 03:08:01

标签: asp.net .net sql vb.net

所以我试图仅从数据库中检索日期,但随后它总是随着时间而来,我不知道为什么,但我数据库中该字段的数据类型是日期。现在,如何检索仅包含日期的数据。

这是我的代码:

            Dim strA As String = ddlSChedName.SelectedValue.ToString()
            sqlcon = New SqlConnection(conString)
            sqlcon.Open()
            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM dbo.CS_refSched WHERE
            SchedID=" + strA + "", sqlcon)
            Dim ds As New DataSet
            Dim da As New SqlDataAdapter
            Dim dt As New DataTable
            da.SelectCommand = cmd
            da.Fill(ds)
            dt = ds.Tables(0)
            sqlcon.Close()

            Dim a1 As String = dt.Rows(0)("From").ToString()
            Dim b As String = dt.Rows(0)("To").ToString()
            Dim c As String = dt.Rows(0)("SetID").ToString()

5 个答案:

答案 0 :(得分:3)

使用符合您的文化/区域设置的DateTime.ToShortDateString()

答案 1 :(得分:2)

一种方法是转换日期(我假设是“To”和“From”)并将它们输出为仅包含日期的字符串

Dim strA As String = ddlSChedName.SelectedValue.ToString()
sqlcon = New SqlConnection(conString)
sqlcon.Open()
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM dbo.CS_refSched WHERE SchedID=" + strA + "", sqlcon)
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Dim dt As New DataTable
da.SelectCommand = cmd
da.Fill(ds)
dt = ds.Tables(0)
sqlcon.Close()

Dim a1 As String = cDate(dt.Rows(0)("From")).ToString("d")
Dim b As String = cDate(dt.Rows(0)("To")).ToString("d")
Dim c As String = dt.Rows(0)("SetID").ToString()

答案 2 :(得分:0)

你也可以用它来检索

date.toString("MM/dd/yyyy")

答案 3 :(得分:0)

Dim a1 As String = cDate(dt.Rows(0)(“From”))。ToString(“d”)。子串(0,10)

答案 4 :(得分:0)

仅在sql server中存储日期 创建自己的数据类型

create type Date from dateTime

inserting only date in a column in sql server