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

2019-03-22 10:04发布

问题:

This question already has an answer here:

  • How to return only the Date from a SQL Server DateTime datatype 38 answers

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'.

回答1:

If you are using SQL Server 2008 or later

select convert(date, getdate())

Otherwise

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


回答2:

try this:

select convert (date ,getdate())

or

select CAST (getdate() as DATE)

or

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


回答3:

Try this:

SELECT CONVERT(date, GETDATE())


回答4:

SELECT CONVERT(date, GETDATE())


回答5:

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

or

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