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
 Help with GetDate()

Author  Topic 

ALindy
Starting Member

3 Posts

Posted - 2009-10-06 : 09:37:29
I am using GetDate to pull data from today and earlier.

SELECT*
WHERE
(TMOS_Data.DueOnDock<=GetDate())

I want to pull data from 5 days from today and earlier

(TMOS_Data.DueOnDock<=GetDate ?+5 days? ())

Any help would be appreciated.

Thanks,
ALindy

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-06 : 09:43:07
SELECT*
WHERE
(TMOS_Data.DueOnDock<=GetDate()+5)

Madhivanan

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

ALindy
Starting Member

3 Posts

Posted - 2009-10-06 : 10:06:28
Thanks! that worked perfectly.

Thanks,
ALindy
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-06 : 10:14:46
quote:
Originally posted by madhivanan
(TMOS_Data.DueOnDock<=GetDate()+5)



5 Days in the future?


SELECT *
FROM @t99
WHERE TMOS_Data.DueOnDock > SELECT DATEADD(dd,-5, CONVERT(varchar(10), GetDate(),1))





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-07 : 01:54:03
quote:
Originally posted by X002548

quote:
Originally posted by madhivanan
(TMOS_Data.DueOnDock<=GetDate()+5)



5 Days in the future?


SELECT *
FROM @t99
WHERE TMOS_Data.DueOnDock > SELECT DATEADD(dd,-5, CONVERT(varchar(10), GetDate(),1))





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam






See what OP specified

I want to pull data from 5 days from today and earlier

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-07 : 02:05:49
I would interpret that statement as Brett

"from today and earlier" to me will be a past date.


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

Go to Top of Page

winterh
Posting Yak Master

127 Posts

Posted - 2009-10-07 : 04:55:49
quote:

I want to pull data from 5 days from today and earlier

Madhivanan

Failing to plan is Planning to fail



Dang Noobs, read it properly, Madhivanan was right! lol. I am sorry, I am the only noob here. :)


[ /fail at query]
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-07 : 06:29:33
ALindy wrote:
quote:
Thanks! that worked perfectly.


So what?
We cannot assume that ALindy isn't able to decide if the result is right or wrong!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-07 : 09:31:57
Well...if you want to be picky

The MIN(Statement_Row_Num)) Says:

quote:
Originally posted by ALindy

I am using GetDate to pull data from today and earlier.



Then he goes no to say...

quote:

I want to pull data from 5 days from today and earlier




And then the code



SELECT*
WHERE
(TMOS_Data.DueOnDock<=GetDate())


Which initmates in the past

But then everyone sees this


(TMOS_Data.DueOnDock<=GetDate ?+5 days? ())


which is the ONLY thing that leads us to the discussion of future dates....which I think is a mistake




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ALindy
Starting Member

3 Posts

Posted - 2009-10-07 : 09:48:04
Hi everyone. To clear things up... I was pulling Due on Dock information for everything that was late and DOD today. I wanted to change that to pull everything that was late AND everything DOD in the next week, so that would be 5 days in the future, today, and all past DOD shipments. For my simple query, (TMOS_Data.DueOnDock<=GetDate()+5) got me exattly what I wanted. Thanks for all of your interest.

Thanks,
ALindy
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-07 : 09:52:58
quote:
Originally posted by ALindy

Hi everyone. To clear things up... I was pulling Due on Dock information for everything that was late and DOD today. I wanted to change that to pull everything that was late AND everything DOD in the next week, so that would be 5 days in the future, today, and all past DOD shipments. For my simple query, (TMOS_Data.DueOnDock<=GetDate()+5) got me exattly what I wanted. Thanks for all of your interest.

Thanks,
ALindy


Ok. This clears up the things

Madhivanan

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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-07 : 10:00:13
I think it wasn't picky to say that ALindy should be able to decide if the result is right or wrong.
But anyway Brett - you're right in having doubts because of that irritating text.

friends?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-07 : 11:19:25
quote:
Originally posted by webfred

I think it wasn't picky to say that ALindy should be able to decide if the result is right or wrong.
But anyway Brett - you're right in having doubts because of that irritating text.

friends?


No, you're never too old to Yak'n'Roll if you're too young to die.



Friends...plovers no more



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -