Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 to find a Day wtih Start and End Time of the day

Author  Topic 

hey001us
Posting Yak Master

185 Posts

Posted - 2010-05-13 : 19:49:45
Is this correct way?
SELECt DATEADD(DD, DATEDIFF( DD, 1, GETDATE()),0),
DATEADD( ms, 86399996, DATEADD(DD, DATEDIFF( DD, 1, GETDATE()),0))

Output: 2010-05-13 00:00:00.000 As StartDay, 2010-05-13 23:59:59.997 EndDay
hey

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-14 : 02:53:25
quote:
Originally posted by hey001us

Is this correct way?
SELECt DATEADD(DD, DATEDIFF( DD, 1, GETDATE()),0),
DATEADD( ms, 86399996, DATEADD(DD, DATEDIFF( DD, 1, GETDATE()),0))

Output: 2010-05-13 00:00:00.000 As StartDay, 2010-05-13 23:59:59.997 EndDay
hey


This is not reliable and may change depends on the version you are using. If you want to find out all data of yesterday regardless of time, use


where
date_col>=dateadd(day,datediff(day,0,getdate())-1,0) and
date_col<dateadd(day,datediff(day,0,getdate()),0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -