Reputation: 89
I am trying to figure out how to get the number of days between these two days shown in a separate column called "Days" I tried using the DATEDIFF function but could not seem to get that to work. Any suggestions? the query works fine otherwise to accomplish all my other needs.
SELECT
Orders.OrderID,
Customers.CompanyName,
(OrderDetails.Quantity * OrderDetails.UnitPrice) AS OrderCost,
FORMAT(Orders.ShippedDate, 'MMM dd yyyy') AS ShippedDate
FROM
Customers
INNER JOIN
Orders ON Customers.CustomerID = Orders.CustomerID
INNER JOIN
OrderDetails ON Orders.OrderID = OrderDetails.OrderID
WHERE
ShippedDate >= '1994-01-01' AND ShippedDate <= '1994-01-31'
ORDER BY
Orders.OrderID, CompanyName, ShippedDate, Orders.OrderDate
Here is what I am trying to achieve:
And here is my current result from the query:
Upvotes: 0
Views: 292
Reputation: 3197
Try adding the following to the select clause ... DATEDIFF(DAY, ShippedDate, Orders.OrderDate)
AS days
Upvotes: 1