|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
set datetime month from intcurrent @thedate value. I need to SET @thedate.year to the @year value. Any suggestions? Thanks, Randy declare @month int set @month = 3 declare @year int set @year = 1999 declare @thedate datetime set @thedate = GetDate() set @thedate = dateadd(yy, @year, @thedate) print @thedate -- Randy randy1200 wrote:
> The problem with the code below is that it ADDS the value of @year to the Try this:> current @thedate value. I need to SET @thedate.year to the @year value. Any > suggestions? DECLARE @month INT SET @month = 3 DECLARE @year INT SET @year = 1999 DECLARE @thedate DATETIME SET @thedate = GETDATE() SET @thedate = dateadd( yy, datediff(yy, '1/1/' + CONVERT(VARCHAR, @year), @thedate) * -1, @thedate) PRINT @thedate declare @month int
set @month = 3 declare @year int set @year = 1999 declare @thedate datetime set @thedate = GetDate() set @thedate = dateadd(yy, @year - Year(@thedate), @thedate) print @thedate Tom Show quote "randy1200" <randy1200@newsgroups.nospam> wrote in message news:DCD1844B-DD6F-4C5C-98A1-56FB4D39CC8A@microsoft.com... > The problem with the code below is that it ADDS the value of @year to the > current @thedate value. I need to SET @thedate.year to the @year value. > Any > suggestions? > > Thanks, > Randy > > > declare @month int > set @month = 3 > declare @year int > set @year = 1999 > > declare @thedate datetime > set @thedate = GetDate() > set @thedate = dateadd(yy, @year, @thedate) > print @thedate > -- > Randy Great responses! Many thanks...
-- Show quoteRandy "randy1200" wrote: > The problem with the code below is that it ADDS the value of @year to the > current @thedate value. I need to SET @thedate.year to the @year value. Any > suggestions? > > Thanks, > Randy > > > declare @month int > set @month = 3 > declare @year int > set @year = 1999 > > declare @thedate datetime > set @thedate = GetDate() > set @thedate = dateadd(yy, @year, @thedate) > print @thedate > -- > Randy |
|||||||||||||||||||||||