How to get just the date part of getdate()?

Sql ServerTsql

Sql Server Problem Overview


I have a SQL table that has a CreationDate field.

I have getdate() in the computed column specification formula.

I would like to know how to get just the date portion, that is, '2012-08-24' instead of '2012-08-24 10:45:17.740'.

Sql Server Solutions


Solution 1 - Sql Server

If you are using SQL Server 2008 or later

select convert(date, getdate())

Otherwise

select convert(varchar(10), getdate(),120)

Solution 2 - Sql Server

try this:

select convert (date ,getdate())

or

select CAST (getdate() as DATE)

or

select convert(varchar(10), getdate(),121)

Solution 3 - Sql Server

Try this:

SELECT CONVERT(date, GETDATE())

Solution 4 - Sql Server

SELECT CONVERT(date, GETDATE())

Solution 5 - Sql Server

SELECT CAST(FLOOR(CAST(GETDATE() AS float)) as datetime)

or

SELECT CONVERT(datetime,FLOOR(CONVERT(float,GETDATE())))

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRui MartinsView Question on Stackoverflow
Solution 1 - Sql ServerpodiluskaView Answer on Stackoverflow
Solution 2 - Sql ServerJoe G JosephView Answer on Stackoverflow
Solution 3 - Sql ServerAndrás OttóView Answer on Stackoverflow
Solution 4 - Sql ServerJohn WooView Answer on Stackoverflow
Solution 5 - Sql ServerAkkarapon S.View Answer on Stackoverflow