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
 Dates

Author  Topic 

Rach2009
Starting Member

37 Posts

Posted - 2010-02-22 : 10:29:33
Hi,

I need to write a simple query with a WHERE clause that is in the form of date=yesterday's date. Is there a simple way of doing this?

I have tried experimenting with getdate() but found two problems with this:-

-Firstly, I do not want the time part to appear at all
-Also, I need the date to appear in dmy format, as opposed to mdy

Any ideas?

Many Thanks

Rachel

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-22 : 10:40:10
[code]
where date >= dateadd(day, datediff(day, 0, getdate()), -1)
and date < dateadd(day, datediff(day, 0, getdate()), 0)
[/code]


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-22 : 10:47:27
quote:
Originally posted by Rach2009

Hi,

I need to write a simple query with a WHERE clause that is in the form of date=yesterday's date. Is there a simple way of doing this?

I have tried experimenting with getdate() but found two problems with this:-

-Firstly, I do not want the time part to appear at all
-Also, I need the date to appear in dmy format, as opposed to mdy

Any ideas?

Many Thanks

Rachel


thats a formatting issue. you need to use formatting functions available at your front end for that. Just retrieve it as it is stored in table and do formatting at front end

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

Go to Top of Page

Rach2009
Starting Member

37 Posts

Posted - 2010-02-23 : 04:13:28
Many thanks to both!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-23 : 09:31:38
welcome

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

Go to Top of Page
   

- Advertisement -