Results 1 to 5 of 5

Thread: Datepart

  1. #1
    kelvin Guest

    Datepart

    Why would this return a year of 1905: If @tempdate was a varchar
    it would return just 2001, but by it being a dateime it returns
    the year 1905.

    declare @tempdate datetime
    select @tempdate = (select datepart(yy,getdate()))
    select @tempdate


  2. #2
    hiku Guest

    Datepart (reply)


    ------------
    kelvin at 5/7/01 1:26:40 PM

    Why would this return a year of 1905: If @tempdate was a varchar
    it would return just 2001, but by it being a dateime it returns
    the year 1905.

    declare @tempdate datetime
    select @tempdate = (select datepart(yy,getdate()))
    select @tempdate


  3. #3
    jharwood Guest

    Datepart (reply)

    Try using "declare @tempdate varchar(4)" instead of datetime.....
    I believe that sql server is ignoring your select because it's not an explicite datetime value and selecting from it's base line.
    Look up datetime in BOL.

    J


    kelvin at 5/7/01 1:26:40 PM

    Why would this return a year of 1905: If @tempdate was a varchar
    it would return just 2001, but by it being a dateime it returns
    the year 1905.

    declare @tempdate datetime
    select @tempdate = (select datepart(yy,getdate()))
    select @tempdate


  4. #4
    Ananth Guest

    Datepart (reply)

    SQL Server internally stores a date as the number of days from 01/01/1900. (the minute and second information is stored in another 4 byte integer which we don't get to see...). So when you take the year of getdate(), you get 2001. This translates to 1905-06-25. Try SELECT CONVERT(datetime, 2001) - it will return the same result. You can also try SELECT DATEADD(day, 2001, '01/01/1900&#39



    ------------
    jharwood at 5/7/01 1:53:35 PM

    Try using "declare @tempdate varchar(4)" instead of datetime.....
    I believe that sql server is ignoring your select because it's not an explicite datetime value and selecting from it's base line.
    Look up datetime in BOL.

    J


    kelvin at 5/7/01 1:26:40 PM

    Why would this return a year of 1905: If @tempdate was a varchar
    it would return just 2001, but by it being a dateime it returns
    the year 1905.

    declare @tempdate datetime
    select @tempdate = (select datepart(yy,getdate()))
    select @tempdate


  5. #5
    dba723 Guest

    Datepart (reply)

    The reason it's converting it to mmdd1905 because you are feeding the datetime variable the number 2001, rather than '2001'.

    Try this:

    select @tempdate = (select convert(char,datepart(yy,getdate())) )


    ------------
    jharwood at 5/7/01 1:53:35 PM

    Try using "declare @tempdate varchar(4)" instead of datetime.....
    I believe that sql server is ignoring your select because it's not an explicite datetime value and selecting from it's base line.
    Look up datetime in BOL.

    J


    kelvin at 5/7/01 1:26:40 PM

    Why would this return a year of 1905: If @tempdate was a varchar
    it would return just 2001, but by it being a dateime it returns
    the year 1905.

    declare @tempdate datetime
    select @tempdate = (select datepart(yy,getdate()))
    select @tempdate


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •