4> CREATE TABLE Orders (
5> OrderID int IDENTITY (1, 1) NOT NULL ,
6> CustomerID nchar (5) NULL ,
7> EmployeeID int NULL ,
8> OrderDate datetime NULL ,
9> RequiredDate datetime NULL ,
10> ShippedDate datetime NULL ,
11> ShipVia int NULL ,
12> Freight money NULL DEFAULT (0),
13> ShipName nvarchar (40) NULL ,
14> ShipAddress nvarchar (60) NULL ,
15> ShipCity nvarchar (15) NULL ,
16> ShipRegion nvarchar (15) NULL ,
17> ShipPostalCode nvarchar (10) NULL ,
18> ShipCountry nvarchar (15) NULL
19> )
20> GO
1>
2>
3>
4> SELECT OrderID, OrderDate
5> FROM dbo.Orders
6> WHERE DATEDIFF(day, '19000102', OrderDate) % 7 = 0;
7> GO
OrderID OrderDate
----------- -----------------------
(0 rows affected)
1>
2> drop table Orders;
3> GO
1>
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 |