------------------------------------------------------------------------
-- John David Ayers ----------------------------------------------------
-- September 29, 2009 --------------------------------------------------
-- SELECT COMMAND 5 ----------------------------------------------------
------------------------------------------------------------------------

-- Add Time to a date
SELECT  OrderDate,
ShipDate,
DATEADD(dd,30,ShipDate) AS [Invoice Due Date]
FROM Orders;

-- Convert
SELECT  CONVERT(CHAR(12),OrderDate,107) AS [Order Date],
CONVERT(CHAR(10),ShipDate,101) AS [Ship Date],
CONVERT(CHAR(12),DATEADD(dd,30,ShipDate), 110) AS [Invoice Due Date]
FROM Orders;

-- Date Difference (Specific Date)
SELECT DATEDIFF(dd, GETDATE(), '10-19-2009') AS [Days till Fall Break];

SELECT DATEDIFF(yy, '12-12-2002', GETDATE()) AS [AGE];

-- Showing DATES
SELECT  YEAR(GETDATE()),
DAY(GETDATE()),
MONTH(GETDATE());

SELECT DATEPART(mm, GETDATE()), DATEPART(dd, GETDATE()), DATEPART(yy, GETDATE());

-- Cast
SELECT 'The Retail Price of ' + ProductName + ' is ' + CAST(RetailPrice AS VarCHAR(10))
FROM Products;

-- NULL
SELECT ISNULL(ProductDescription, 'Nothing')
FROM Products;
