SQL Server – Get Time in Hour:Minute Format from a Datetime – Get Date Part Only from Datetime

--> (Word) --> (PDF) --> (Epub)
This article has been published [fromdate]

I have seen scores of expert developers getting perplexed with SQL Server in finding time only from datetime datatype. Let us have a quick glance look at the solution.

[tab:SQL Server 2000/2005]

SQL Server 2000/2005

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

datetime2005

[tab:SQL Server 2008]

SQL Server 2008

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

datetime2008

[tab:END]

I hope the above solution is clear to you all.

SOURCE

LINK (Blog.sqlauthority.com)

LANGUAGE
ENGLISH