如何只显示sql结果中的日期

时间:2015-08-11 13:00:12

标签: sql asp.net vb.net

 Dim sel As String = "select * from personal_i where number= @number"
            Dim adapter As New SqlDataAdapter(sel, conn)
            adapter.SelectCommand.Parameters.AddWithValue("@number", Label61.Text)
            Dim dataset As New DataSet
            adapter.Fill(dataset)
 Label1.Text = dataset.Tables(0).Rows(0).Item(6).ToString

结果是:

  

8/7/2015 12:00:00 AM

如何仅显示日期,而不是时间?

3 个答案:

答案 0 :(得分:1)

您正在寻找格式化功能。

 Label1.Text = Format(dataset.Tables(0).Rows(0).Item(6).ToString, “Short Date”)

答案 1 :(得分:0)

我会建议像:

    Dim sel As String = "select * from personal_i where number= @number"
                Dim adapter As New SqlDataAdapter(sel, conn)
                adapter.SelectCommand.Parameters.AddWithValue("@number", Label61.Text)
                Dim dataset As New DataSet
                adapter.Fill(dataset)

     Label1.Text = Format(Trim(Split(dataset.Tables(0).Rows(0).Item(6).ToString," ")(0)),"m/d/yyyy")

答案 2 :(得分:-1)

Label1.Text = dataset.Tables(0).Rows(0).Item(6).ToString(dd / MM / yyy)

我建议您在查询命令中执行此操作,例如

SELECT TO_CHAR(Col_Name,'dd-mm-yyyy') from Table_name where CONDITION;