datetime

  • I have a sql query like

    select count(*) from GeneralBooks group by orderdate

    where orderdate is a datetime column in the database table which stores the date and time, but when I execute the above the query it should only take into consideration the date part of the orderdate value and not consider the time part.

    How do I separate it out, so that I can group by orderdate based only on the date and not time.

    Thank you.

  • Use one of the many CONVERT formats. Eg:

    select convert(varchar(10), orderdate, 120), count(*) from GeneralBooks group by convert(varchar(10), orderdate, 120) order by 1

    Cheers,

    - Mark


    Cheers,
    - Mark

Viewing 2 posts - 1 through 1 (of 1 total)

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