Home All Groups Group Topic Archive Search About
Author
10 Nov 2005 5:59 PM
scott
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

Author
10 Nov 2005 6:10 PM
Raymond D'Anjou
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
>
Author
11 Nov 2005 12:20 AM
Scott
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
>>
>
>
Author
11 Nov 2005 12:21 AM
Scott
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
>>
>
>
Author
10 Nov 2005 6:19 PM
John Scragg
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
>
>
>
Author
10 Nov 2005 6:41 PM
Aaron Bertrand [SQL Server MVP]
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
>

AddThis Social Bookmark Button