Datetime in sqlserver 2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raj

    Datetime in sqlserver 2005

    Hi,

    I have a table which has a column of type datetime,i want to write a
    query where i can get only year from my datetime column.


    2004-11-16 00:00:00.000 this is the one which i have i required only
    2004 on selecting.

    Thanks in Advance
    Raj
  • Roy Harvey (SQL Server MVP)

    #2
    Re: Datetime in sqlserver 2005

    On Wed, 8 Oct 2008 19:06:09 -0700 (PDT), raj <2rajesh.b@gmai l.com>
    wrote:
    >I have a table which has a column of type datetime,i want to write a
    >query where i can get only year from my datetime column.
    >
    >2004-11-16 00:00:00.000 this is the one which i have i required only
    >2004 on selecting.
    SELECT datepart(year,d atetimecolumn)
    FROM Whatever

    Note that this returns an INT datatype.

    Roy Harvey
    Beacon Falls, CT

    Comment

    • sqlmonkey

      #3
      Re: Datetime in sqlserver 2005

      On Oct 9, 3:06 am, raj <2rajes...@gmai l.comwrote:
      Hi,
      >
      I have a table which has a column of type datetime,i want to write a
      query where i can get only year from my datetime column.
      >
      2004-11-16 00:00:00.000 this is the one which i have i required only
      2004 on selecting.
      >
      Thanks in Advance
      Raj
      select year(datetimeco lumn) from table

      Comment

      Working...