如何在VB.net中使用date_format

时间:2014-01-13 07:29:33

标签: asp.net vb.net visual-studio-2008

我想从datetime数据类型列获取serparted的日期和时间。 这是我的以下代码:

sqlgetInfo = "SELECT Name, DATE_FORMAT(recordTime, '%d %b %Y') AS date, DATE_FORMAT(recordTime, '%T') AS time FROM logTracker WHERE actionType = 'update' AND reportType = 'BM'"

Dim infoAdapter As New SqlDataAdapter(sqlgetInfo, Conn)
Dim infoTable As DataTable
Dim infoDataSet As New DataSet()
infoAdapter.Fill(infoDataSet, "info")
infoTable = infoDataSet.Tables("info")
For Each infoRow As DataRow In infoTable.Rows
    Response.Write("<td>" & infoRow("Name") & "/" & infoRow("date") & "/" & infoRow("time") & "</td>")
Next
Response.Write("</tr>")

不知何故,当我运行它时,像'DATE_FORMAT'这样的错误不是公认的内置函数名称

1 个答案:

答案 0 :(得分:0)

在sql-query中使用内置函数CONVERT

SELECT Name
, CONVERT(VARCHAR(10), recordTime, 104) AS date
, CONVERT(VARCHAR(8), recordTime, 108) AS time 
FROM logTracker WHERE actionType = 'update' AND reportType = 'BM'"

参数104108style of date format的情况 选择能够更好地满足您需求的样式格式......