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.
Yaro,
Thanks for the tip. It’s better than the solution provided in the post.
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
How to display Date Only Format in GridView
How to Get First and Last Date of a month?