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.
| Author |
Topic |
|
Trudye
Posting Yak Master
169 Posts |
Posted - 2008-08-27 : 12:35:36
|
| I am trying to subtract 90 days from getdate and have the output format be yyyymmdd, But I keep getting May 29 2008May 29 2I am using the following codeDeclare @Min_Date as nvarchar (8)Declare @Min_Date2 as nvarchar (11)SET @Min_Date2 = DATEADD (day, -90, getdate()) Print @Min_Date2SET @Min_Date = (SELECT CONVERT(VARCHAR(8), @Min_Date2, 112)Print @Min_DateAny words of wisdom?Thanx,Trudye |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-08-27 : 12:39:28
|
when converting from varchar to varchar the 3rd parameter has noeffect.Declare @Min_Date as nvarchar (8)Declare @Min_Date2 as nvarchar (11)SET @Min_Date2 = DATEADD (day, -90, getdate()) select @Min_Date2SELECT @Min_Date = CONVERT(NVARCHAR(8), DATEADD (day, -90, getdate()), 112)select @Min_Date _______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-27 : 12:51:50
|
quote: Originally posted by Trudye I am trying to subtract 90 days from getdate and have the output format be yyyymmdd, But I keep getting May 29 2008May 29 2I am using the following codeDeclare @Min_Date as nvarchar (8)Declare @Min_Date2 as nvarchar (11)SET @Min_Date2 = DATEADD (day, -90, getdate()) Print @Min_Date2SET @Min_Date = (SELECT CONVERT(VARCHAR(8), @Min_Date2, 112)Print @Min_DateAny words of wisdom?Thanx,Trudye
why are you having varchar variables for storing dates?Wont this be enough?Declare @Min_Date as datetimeSET @Min_Date=DATEADD(d,DATEDIFF(d,0,GETDATE())-90,0) |
 |
|
|
Trudye
Posting Yak Master
169 Posts |
Posted - 2008-08-27 : 12:56:11
|
| Thank you so much, visakh16 (my very knowledable consultant) and spirit1 (I will add your code and your comment to my cheat sheet file), and tkizer thank you also.Be well,Trudye |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-27 : 12:58:15
|
quote: Originally posted by Trudye Thank you so much, visakh16 (my very knowledable consultant) and spirit1 (I will add your code and your comment to my cheat sheet file), and tkizer thank you also.Be well,Trudye
You're welcome |
 |
|
|
|
|
|
|
|