want only date from date-time format

  • Hi All, I'm new to sql. Of late I created a table (in sql 2000) using

    create table EMP

    (

    EMPNO int,

    ENAMECHAR(10),

    JOBCHAR(10),

    MGRINT null,

    HIREDATE DATETIME,

    SALINT,

    COMMINT NULL,

    DEPTNOINT

    )

    the table looked like ...

    7369SMITH HEADCLERK 75661980-12-17 00:00:00.000800NULL20

    7499ALLEN SALESMAN 76981981-02-20 00:00:00.000160030030

    7521WARD SALESMAN 76981981-02-22 00:00:00.000290050030

    I want to get rid of that time part in the 'HireDate' column. I want only 1980-12-17 instead of 1980-12-17 00:00:00.000. please help me. Is declaring HIREDATE as a DATETIME incorrect? SQL 2000 perhaps does not accept DATE as data type, so I used DATETIME.

    Also, if possible provide me a link from where I can study cast, convert & other similar utilities(sql 2000).

    Thanking you in anticipation,

  • It doesn't matter how it looks like in a table, but it is important how it looks like when you retrieve a data. So, you can convert it into different formats inside any of your SELECT statement like that:

    SELECT CONVERT(CHAR(10), HIREDATE, 111) or

    SELECT CONVERT(CHAR(10), HIREDATE, 105)

    instead of just SELECT HIREDATE

  • THANKS Sergey .. it worked.... 🙂

  • SQL Server 2008 has a Date datatype which will solve your problem when you are able to upgrade.

    http://brittcluff.blogspot.com/

  • Lynn has a nice page of common date routines at:

    http://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply