Use of DATEPART() in Sql

Bageshkumarbagi
Posted by Bageshkumarbagi under SQL Server category on | Points: 40 | Views : 1370
Hi,

SELECT DATEPART(year, GETDATE()) AS 'Year'
SELECT DATEPART(month, GETDATE()) AS 'Month'
SELECT DATEPART(hour, GETDATE()) AS 'Hour'
SELECT DATEPART(day, GETDATE()) AS 'day'
SELECT DATEPART(DAYOFYEAR, GETDATE()) AS 'day'
SELECT DATEPART(DD, GETDATE()) AS 'day'
SELECT DATEPART(DW, GETDATE()) AS 'day of the week'
SELECT DATEPART(HH, GETDATE()) AS 'HH'
SELECT DATEPART(ISO_WEEK, GETDATE()) AS 'no of week'
SELECT DATEPART(ISOWK, GETDATE()) AS 'Current week'
SELECT DATEPART(M, GETDATE()) AS 'Month'
SELECT DATEPART(MCS, GETDATE()) AS 'Micoseconds'
SELECT DATEPART(MINUTE, GETDATE()) AS 'Minute'
SELECT DATEPART(N, GETDATE())
SELECT DATEPART(Q, GETDATE()) AS 'Quarter'
SELECT DATEPART(QUARTER, GETDATE()) AS 'Quarter'
SELECT DATEPART(SECOND, GETDATE()) AS 'Seconds'
SELECT DATEPART(SS, GETDATE()) AS 'seconds'
SELECT DATEPART(TZOFFSET, GETDATE()) AS 'Time Zone'
SELECT DATEPART(WEEK, GETDATE()) AS 'Week'
SELECT DATEPART(WEEKDAY, GETDATE()) AS 'Week Day'
SELECT DATEPART(YEAR, GETDATE()) AS 'Year'
SELECT DATEPART(YYYY, GETDATE()) AS 'Year'

Comments or Responses

Posted by: Bandi on: 9/2/2013 Level:Platinum | Status: [Member] [MVP] | Points: 10
Hi Bagesh Kumar Singh,
The following first SELECT gives me error....
SELECT DATEPART(TZoffset, GETDATE()) AS 'Time Zone'   -- Error: The datepart tzoffset is not supported by date function datepart for data type void type.

SELECT DATEPART(TZoffset, SYSDATETIME()) AS 'Time Zone' -- Gives output 0... This is fine

Login to post response