下表是我的数据库(测试),现在我想将事件部分分为年,月,日!!我最近发现datepart不起作用!还有其他功能我可以使用它!
id | event | sensor | MAC
649| 2014-12-18 13:40:01 | 24951484857695552516667503 | 0xDE0xAD0xBE0xEF0xFE0xED
650| 2014-12-18 13:50:38 | 24951484857695552516667503 | 0xDE0xAD0xBE0xEF0xFE0xED
这是我想要使用的例子
SELECT DATEPART(yyyy,OrderDate) AS OrderYear,
DATEPART(mm,OrderDate) AS OrderMonth,
DATEPART(dd,OrderDate) AS OrderDay
FROM Orders
WHERE OrderId=1
其结果将是: 将导致这个:
OrderYear OrderMonth OrderDay
2008 11 11
答案 0 :(得分:0)
SELECT year(OrderDate) AS OrderYear,
month(OrderDate) AS OrderMonth,
dayofmonth(OrderDate) AS OrderDay
FROM Orders
WHERE OrderId = 1