问题
Much like this question: "How to get Time from DateTime format in SQL?", I am trying to select only the time from a datetime, but unlike the above question, I would like to know how to do it in SQL Server Compact
. Does anyone know how to do this?
回答1:
SELECT DATEPART(hour, OrderDate), DATEPART(minute, OrderDate) FROM MyOrders
Ref. http://msdn.microsoft.com//library/ms173998%28v=sql.90%29.aspx
回答2:
Solved it. Luigi's answer is not actually the correct one but I have upvoted it, as it helped me find the answer.
To get only the time from a datetime in SQL Server Compact
, the proper query is:
select ltrim(str(DATEPART(hour, columnName))) + ':' + ltrim(str(DATEPART(minute, columnName))) + ':' + ltrim(str(DATEPART(second, columnName))) from table
来源:https://stackoverflow.com/questions/15760696/select-time-from-datetime-in-sql-compact