How to get time part from SQL Server 2005 datetime

2020-02-10 02:56发布

How to get time part from SQL Server 2005 datetime in HH:mm tt format

E.g.

11:25 AM
14:36 PM

9条回答
戒情不戒烟
2楼-- · 2020-02-10 03:23
select cast(getdate() as time)) [time],
查看更多
劳资没心,怎么记你
3楼-- · 2020-02-10 03:24

SQL Server 2008

SELECT
CONVERT(TIME,GETDATE()) AS HourMinuteSecond,
CONVERT(DATE,GETDATE(),101) AS DateOnly
GO

Result

HourMinuteSecond: 13:06:56.5770000
DateOnly:         2012-07-26

SQL Server 2000/2005

SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond,
CONVERT(VARCHAR(8),GETDATE(),101) AS DateOnly
GO

http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/

查看更多
We Are One
4楼-- · 2020-02-10 03:32

SQL Server 2008

SELECT
CONVERT(TIME,GETDATE()) AS HourMinuteSecond,
CONVERT(DATE,GETDATE(),101) AS DateOnly
GO

Result:

HourMinuteSecond: 13:06:56.5770000
DateOnly:         2012-07-26

SQL Server 2000/2005

SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond,
CONVERT(VARCHAR(8),GETDATE(),101) AS DateOnly
GO
查看更多
登录 后发表回答