Tuesday, December 22, 2009

As database developers, one of the most common task we usually perform on a SQL script is to extract time only from the current DateTime value. This is easy on MS SQL Server database. Here are few lines of sql script that you can copy. The code separates the time in Hour:Minute format and also the date from the current datetime.


SQL Server 2000/2005


SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinSec,
CONVERT(VARCHAR(8),GETDATE(),101) AS DateAlone
GO

SQL Server 2008


SELECT
CONVERT(TIME,GETDATE()) AS HourMinSec,
CONVERT(DATE,GETDATE(),101) AS DateAlone
GO


To stay up-to-date on Technology news, subscribe now.

0 comments:

Post a Comment