Varieties of dates available in sql server :-


Declare @Date datetime

SET @Date = '1/1/2011'

WHILE @Date < '1/1/2012'
BEGIN
SELECT
CONVERT(VARCHAR(8), @Date, 112) date1, @Date fulldate, YEAR(@Date) years,
DATEPART(qq, @Date) quater, DATEPART(ww, @Date) yearweeks, DATENAME(dw, @Date) dayname,
DATEPART(dd, @Date) dateno, DATENAME(mm, @Date) monthnam, DATEPART(dy,@Date) daycnt,
DATENAME(mm, @Date) + ' ' + CAST(DATEPART(dd, @Date) AS CHAR(2)) + ',' + CAST(DATEPART(yy, @Date) AS CHAR(4)) [mm dd,yyyy],
CONVERT(VARCHAR(10), @Date, 101) normaldate,
DATEPART(dw, @Date) ,
DATEPART(mm, @Date) dateno

SET @Date = DATEADD(dd, 1, @Date)
END

Comments

Popular posts from this blog