Page 1 of 1

How to Return only the Date from the SQL Server GETDATE() function?

Posted: Thu Jul 18, 2019 4:23 pm
by Ben
How do i only Return the Date from the SQL Server GETDATE() function?

If i run the below

Code: Select all

SELECT GETDATE()
It Returns: 2019-07-18 17:24:13.790

I only want to get the date and remove the time part, for example: 2019-07-18

How can I do this?

Re: How to Return only the Date from the SQL Server GETDATE() function?

Posted: Thu Jul 18, 2019 4:27 pm
by Mitch
Hi,

You can achieve this by doing a CONVERT or CAST on the GETDATE() to a DATE datatype.

For example:

Code: Select all

SELECT CONVERT(date, getdate())
OR

Code: Select all

SELECT CAST(getdate() AS DATE)
Either of these will work.

Thanks