unclejimbob
Technical User
I would like to find midnight of the previous day.
Try the following code:
[tt]
DECLARE @start_date DATETIME
DECLARE @start_date1 DATETIME
DECLARE @start_date2 DATETIME
SET @start_date = getdate()
PRINT cast(@start_date as varchar(50))
SET @start_date1 = DATEDIFF(dd,0,@start_date)
PRINT cast(@start_date1 as varchar(50))
SET @start_date2 = DATEADD(day,DATEDIFF(dd,0,@start_date),0)
PRINT cast(@start_date2 as varchar(50))
[/tt]
Question: why do I need to bother with this...
DATEADD(day,DATEDIFF(dd,0,@start_date),0)
when this...
DATEDIFF(dd,0,@start_date)
returns the same result ?
Is it because without the use of DATEADD I am doing some sort of implicit data conversion ? I've been using the DATEADD(day,DATEDIFF(dd,0,@start_date),0) version for ages but this morning I woke up and thought 'Why am I doing this ?' and here we are.
When replying please remember to use small words and write slowly - so I can follow along ;-)
Try the following code:
[tt]
DECLARE @start_date DATETIME
DECLARE @start_date1 DATETIME
DECLARE @start_date2 DATETIME
SET @start_date = getdate()
PRINT cast(@start_date as varchar(50))
SET @start_date1 = DATEDIFF(dd,0,@start_date)
PRINT cast(@start_date1 as varchar(50))
SET @start_date2 = DATEADD(day,DATEDIFF(dd,0,@start_date),0)
PRINT cast(@start_date2 as varchar(50))
[/tt]
Question: why do I need to bother with this...
DATEADD(day,DATEDIFF(dd,0,@start_date),0)
when this...
DATEDIFF(dd,0,@start_date)
returns the same result ?
Is it because without the use of DATEADD I am doing some sort of implicit data conversion ? I've been using the DATEADD(day,DATEDIFF(dd,0,@start_date),0) version for ages but this morning I woke up and thought 'Why am I doing this ?' and here we are.
When replying please remember to use small words and write slowly - so I can follow along ;-)