DATEPART « Date Functions « SQL Server / T-SQL Tutorial






10.8.DATEPART
10.8.1.DATEPART returns part of a date as an integer value.
10.8.2.Values for the datepart parameter.
10.8.3.WHERE DATEPART(WEEKDAY, pubdate) = 3
10.8.4.where DATEPART(DAY, pubdate) BETWEEN 8 AND 14
10.8.5.where DATEDIFF(WEEK, pubdate, GETDATE()) <= 48
10.8.6.DATEPART Function returns the integer value of the datepart specified: DATEPART(datepart,date)
10.8.7.select DATEPART(day, '2002-09-30 11:35:00')
10.8.8.select DATEPART(month, '2002-09-30 11:35:00')
10.8.9.select DATEPART(year, '2002-09-30 11:35:00')








10.8.10.select DATEPART(hour, '2002-09-30 11:35:00')
10.8.11.select DATEPART(minute, '2002-09-30 11:35:00')
10.8.12.select DATEPART(second, '2002-09-30 11:35:00')
10.8.13.select DATEPART(quarter, '2002-09-30 11:35:00')
10.8.14.select DATEPART(dayofyear, '2002-09-30 11:35:00')
10.8.15.select DATEPART(week, '2002-09-30 11:35:00')
10.8.16.select DATEPART(weekday, '2002-09-30 11:35:00')
10.8.17.select DATEPART(m,'2002-09-30')
10.8.18.SELECT DATEPART(dd, '7/5/99')
10.8.19.SELECT DATEPART(dd, '7/5/00')








10.8.20.IF DATEDIFF(dd, '7/5/99','7/5/00') = 0
10.8.21.(DATEPART(mm, @date1) = DATEPART(mm, @date2))
10.8.22.(DATEPART(dd, @date1) = DATEPART(dd, @date2))
10.8.23.(DATEPART(yy, @date1) = DATEPART(yy, @date2)
10.8.24.Identifying Weekday
10.8.25.Grouping by the Week by using datepart function