我想从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'这样的错误不是公认的内置函数名称
答案 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'"
参数104
和108
是style of date format的情况
选择能够更好地满足您需求的样式格式......