Tech Dreams

Get Date From DateTime Field (SQL Server)

While writing SQL Server queries, often I need to extract date part from DateTime columns/variables and it’s very easy to do that:


SELECT convert(varchar,getdate(),101)

Bonus: How To Retrieve Time Part Alone From DateTime Field

Here is the bonus tip to get the time part alone from DateTime fields


SELECT convert(varchar,getdate(),108)

Hope this helps you.

3 Comments on Get Date From DateTime Field (SQL Server)

  1. Gopinath
    March 2, 2011 at 7:52 pm (9 years ago)

    Yaro,
    Thanks for the tip. It’s better than the solution provided in the post.

    Reply
  2. Yaro
    February 28, 2011 at 8:12 pm (9 years ago)

    This conversion works, but may not be very quick.
    This one should be faster:

    select dateadd(day, datediff(day, 0, getdate()), 0);

    There is a good article on:
    http://dbstandard.com/showthread.php?tid=1

    Reply

Leave a reply