Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date function question 1

Status
Not open for further replies.

gradinumcp

IS-IT--Management
Apr 6, 2005
85
US
Just a quick question:

How does DATEADD(d,-1,DATEDIFF(d,0,GETDATE())) represent yesterday's date...

My explanation which does not fit here is that datediff will do today-0 and will return 8 as today's date is 8th. Then for DateAdd don't we need a date to do the calculation...how does it do 8-1=7 which is yesterday's date?

Please give me a simple explanation for this..and maybe suggestions on other ways to get yesterday's date..

Thanks:)
 
unless your "d" is some kind of variable or column name, this doesn't even run for me.

date_add receives two parameters, a date and an interval. getting yesterday's date is easy:

[tt]SELECT DATE_ADD( now( ) , INTERVAL -1 DAY ) [/tt]



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
select date_sub(curdate(), interval 1 day); # for yesterdays date.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
DATEADD(d,-1,DATEDIFF(d,0,GETDATE())) looks like it was intended for Microsoft SQL Server (but it doesn't work)

gradinumcp, which database system are you using?

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top