, DATEPART , DATETIME ( , ). , , DATEADD "" YYYY-MM-DD 00:00:00.000.
Adventure Works , ( SQL Server 2005). DATEADD @OMG Ponies:
select
dateadd(dd, 0, datediff(dd, 0, OrderDate)) as SaleDay
, sum(taxamt) as Amount
from
Sales.SalesOrderHeader
group by
dateadd(dd, 0, datediff(dd, 0, OrderDate))
order by
SaleDay
The idea dateadd(dd, 0, datediff(dd, 0, OrderDate))is to first get the "number of days that have passed from the beginning of the time to your date" ( datediff-part), and then add this number of days to the "beginning of time". This gives you the "beginning of your day." I hope this is clear :)
source
share