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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Deriving 1 year old dates

Author  Topic 

skybvi
Posting Yak Master

193 Posts

Posted - 2012-01-18 : 12:28:13
Hi,
i am using this code:-

Declare @dt1 datetime,
@dt2 datetime,
@dt3 datetime,
@dt4 datetime

set @dt1 = dateadd(d,-7,GETDATE())
set @dt2 = GETDATE()
set @dt3 = dateadd(d,-8,GETDATE())
set @dt4 = dateadd(d,-1,GETDATE())

I am using all the 4 dates in my sql queries.
I want same dates but last year..

For example...if @dt1 is 14-12-2011
the new @dt5 should be 14-12-2010
I need 1 year old dates beacuse I am comparing sales from last year..


Regards,
Sushant
DBA
Virgin Islands(U.K)

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-01-18 : 12:32:20
Maybe:
SET @dt5 = DATEADD(YEAR, -1, @dt1)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-18 : 12:54:20
do you really THINK we should be helping a DBA who lives and works in the Virgin Islands...I mean..I'm in Newark for god's sake

;-)



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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-18 : 13:35:05
quote:
Originally posted by X002548

do you really THINK we should be helping a DBA who lives and works in the Virgin Islands...I mean..I'm in Newark for god's sake

;-)


Be thankful for what you have, Brett. It's the middle of January and still hasn't snowed yet. Sort of like Virgin Islands.
Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2012-01-18 : 13:46:09
quote:
Originally posted by Lamprey

Maybe:
SET @dt5 = DATEADD(YEAR, -1, @dt1)




thanks, it worked


Regards,
Sushant
DBA
Virgin Islands(U.K)
Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2012-01-18 : 13:46:57
quote:
Originally posted by X002548

do you really THINK we should be helping a DBA who lives and works in the Virgin Islands...I mean..I'm in Newark for god's sake

;-)



Brett

8-)




i didn't get u Brett :(

Regards,
Sushant
DBA
Virgin Islands(U.K)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-18 : 14:02:41
Hey..I like Snow...in the Mountains

http://www.weather.com/weather/tenday/Newark+NJ+USNJ0355

I guess I can't complain..after all it's January

http://www.weather.com/weather/tenday/18.335765,-64.896335

Doesn't look like Beach weather



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


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

skybvi
Posting Yak Master

193 Posts

Posted - 2012-01-18 : 14:16:58
quote:
Originally posted by X002548

Hey..I like Snow...in the Mountains

http://www.weather.com/weather/tenday/Newark+NJ+USNJ0355

I guess I can't complain..after all it's January

http://www.weather.com/weather/tenday/18.335765,-64.896335

Doesn't look like Beach weather

Brett

8-)




I don't like snow thatsy I came from chicago to British Virgin Islands (BVI)...btw the link u gave is of Saint thomas which is USVI, not BVI..
Here in BVI, its beach weather, infact its hotter than beach weather...
Many toursits come here this time of the year to enjoy beach.
Thanks.

Regards,
Sushant
DBA
Virgin Islands(U.K)
Go to Top of Page
   

- Advertisement -