|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Get Current YearWhen I run below code, I get Jun 29 1905 12:00AM.
How can I get 2005 as the current year? CODE: SET @dtYear = DATEPART(yy,GetDate()) PRINT @dtYear I'm going to guess that you're declaring @dtYear as DATETIME.
Declare it as INT. declare @dtYear int SET @dtYear = DATEPART(yy,GetDate()) PRINT @dtYear Show quote "scott" <sbai***@mileslumber.com> wrote in message news:O2slnCi5FHA.620@TK2MSFTNGP12.phx.gbl... > When I run below code, I get Jun 29 1905 12:00AM. > > How can I get 2005 as the current year? > > CODE: > > SET @dtYear = DATEPART(yy,GetDate()) > > PRINT @dtYear >
Show quote
"Raymond D'Anjou" <rdanjou@canatradeNOSPAM.com> wrote in message
news:eWi$IIi5FHA.3588@TK2MSFTNGP15.phx.gbl... > I'm going to guess that you're declaring @dtYear as DATETIME. > Declare it as INT. > > declare @dtYear int > SET @dtYear = DATEPART(yy,GetDate()) > PRINT @dtYear > > "scott" <sbai***@mileslumber.com> wrote in message > news:O2slnCi5FHA.620@TK2MSFTNGP12.phx.gbl... >> When I run below code, I get Jun 29 1905 12:00AM. >> >> How can I get 2005 as the current year? >> >> CODE: >> >> SET @dtYear = DATEPART(yy,GetDate()) >> >> PRINT @dtYear >> > > It was the declare. thanks
Show quote "Raymond D'Anjou" <rdanjou@canatradeNOSPAM.com> wrote in message news:eWi$IIi5FHA.3588@TK2MSFTNGP15.phx.gbl... > I'm going to guess that you're declaring @dtYear as DATETIME. > Declare it as INT. > > declare @dtYear int > SET @dtYear = DATEPART(yy,GetDate()) > PRINT @dtYear > > "scott" <sbai***@mileslumber.com> wrote in message > news:O2slnCi5FHA.620@TK2MSFTNGP12.phx.gbl... >> When I run below code, I get Jun 29 1905 12:00AM. >> >> How can I get 2005 as the current year? >> >> CODE: >> >> SET @dtYear = DATEPART(yy,GetDate()) >> >> PRINT @dtYear >> > > SELECT YEAR(GetDate())
HTH, John Scragg Show quote "scott" wrote: > When I run below code, I get Jun 29 1905 12:00AM. > > How can I get 2005 as the current year? > > CODE: > > SET @dtYear = DATEPART(yy,GetDate()) > > PRINT @dtYear > > > That's looks like 2005 days from the base date, 1900-01-01. Easy to check:
SELECT DATEADD(DAY, 2005, '19000101') Works the same way if you say: DECLARE @dt SMALLDATETIME SET @dt = 2005 SELECT @dt When you pass an INT to a DATETIME it assumes that an INT is the number of days since "0" and it implicitly converts it for you. You forgot to show us your DECLARE statement. DATEPART in this case produces an INT, so please be sure you say: DECLARE @dtYear INT Show quote "scott" <sbai***@mileslumber.com> wrote in message news:O2slnCi5FHA.620@TK2MSFTNGP12.phx.gbl... > When I run below code, I get Jun 29 1905 12:00AM. > > How can I get 2005 as the current year? > > CODE: > > SET @dtYear = DATEPART(yy,GetDate()) > > PRINT @dtYear > |
|||||||||||||||||||||||