SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

414 Posts

Posted - 02/24/2013 :  22:17:28  Show Profile  Reply with Quote
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 - 02/24/2013 :  22:41:28  Show Profile  Reply with Quote
Hope this helps

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

peace
Constraint Violating Yak Guru

414 Posts

Posted - 02/24/2013 :  23:01:33  Show Profile  Reply with Quote
is in where condition
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 02/24/2013 :  23:18:43  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000