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 2008 Forums
 Transact-SQL (2008)
 Now Date

Author  Topic 

tyekhan
Starting Member

29 Posts

Posted - 2014-05-22 : 08:17:26


i need to change the date, so it will allways select yestoday day,
GETDATE() + 1

i have the below query for the date,

WHERE (History.CallDateTime > CONVERT(DATETIME, '2014-05-21 00:00:00', 102))

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-05-22 : 08:34:53
[code]WHERE CallDateTime >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -1)
AND CallDateTime < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

adsingh82
Starting Member

20 Posts

Posted - 2014-05-22 : 09:52:42
Please check the correct sql

WHERE CallDateTime >= CONVERT(DATETIME, '2014-05-21 00:00:00', 102) -1
AND < CONVERT(DATETIME, '2014-05-21 00:00:00', 102) + 1

Regards,
Alwyn.M
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-06-17 : 03:05:01
quote:
Originally posted by adsingh82

Please check the correct sql

WHERE CallDateTime >= CONVERT(DATETIME, '2014-05-21 00:00:00', 102) -1
AND < CONVERT(DATETIME, '2014-05-21 00:00:00', 102) + 1

Regards,
Alwyn.M


khtan's solution is optimal. Do not depend on the date settings

Madhivanan

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

- Advertisement -