Convert Datetime

  • Hi everybody,

    I am using this sql statement:

    SELECT Orderdate

    FROM Northwind.dbo.Orders

    where Orderdate is of datetime type.

    And the Orderdate is displayed in this format:

    1996-07-04 00:00:00.000

    But I wan't to use only the year,month and day. I tryed this statement

    SELECT Orderdate

    FROM Northwind.dbo.Orders

    WHERE OrderDate = CONVERT(varchar, '7/19/1996', 100)

    and still the result is displayed in the aforementioned format

    1996-07-04 00:00:00.000

    Thanks!!!

  • quote:


    SELECT Orderdate

    FROM Northwind.dbo.Orders

    WHERE OrderDate = CONVERT(varchar, '7/19/1996', 100)


    you are still selecting orderdate as a datetime field the where clause does not effect the type returned.

    the CONVERT needs to be done on the result not the where clause

    Mr Peter Livesey


    Mr Peter Livesey

  • try

    SELECT CONVERT(char(12),Northwind.dbo.orderdate,3) as orderdate

    FROM Northwind.dbo.Orders

    see

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_11_77l1.asp

    Mr Peter Livesey

    Edited by - PeterLivesey on 02/05/2002 10:26:53 AM


    Mr Peter Livesey

  • As Peter has said earlier u are selecting the orderdate in datetime format only.You should convert the date into required format while selecting the date like

    select convert(varchar,Northwind.dbo.orderdate,102) as orderdate

    FROM Northwind.dbo.Orders

    the above query will return only the year,month and date and not the time

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

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