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
 General SQL Server Forums
 New to SQL Server Programming
 date

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-02-24 : 22:17:28
i would like to get yesterday's date

YesterdayDate= DATEADD(Day,-1,Cast(getdate() as Date))

hit this error:Type Date is not a defined system type.

theKid27
Starting Member

21 Posts

Posted - 2013-02-24 : 22:41:28
Hope this helps

SELECT DATEADD(day,-1, GETDATE() ) AS "YesterdayDate"
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-02-24 : 23:01:33
is in where condition
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-24 : 23:18:43
date works only from 2008 onwards. you dont need the casting there. just do

WHERE datefield >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()),-1)
AND datefield < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)


see
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

http://visakhm.blogspot.in/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -