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

All topics about programming / development in T-SQL or other languages for SQL Server.
Post Reply
Ben
Posts: 2
Joined: Thu Jul 18, 2019 4:19 pm

Thu Jul 18, 2019 4:23 pm

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?
Mitch
Posts: 1
Joined: Thu Jul 18, 2019 4:24 pm

Thu Jul 18, 2019 4:27 pm

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
Post Reply

Social Media