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

23    Asked by jhone_8449 in SQL Server , Asked on Aug 16, 2025

How can you extract just the date portion from a DateTime value in SQL Server? What functions or conversions let you return only the date without the time part?

Answered by 44rodina

In SQL Server, the DateTime datatype stores both the date and time components together. However, sometimes you may only need the date portion without the time (for example, when displaying birthdates, order dates, or filtering records by day). Luckily, SQL Server provides several ways to achieve this.

Here are some common methods:

Using CAST to DATE (Recommended)

 The simplest and most efficient way is to cast the DateTime value to a DATE type:

 SELECT CAST(GETDATE() AS DATE) AS OnlyDate;

 This returns just the date, discarding the time.

Using CONVERT Function

 You can also use the CONVERT function with a specific style:

 SELECT CONVERT(DATE, GETDATE()) AS OnlyDate;

 This works similarly to CAST but gives you more formatting options if needed.

Formatting with Style Codes

 If you want the date as a formatted string:

 SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS OnlyDate;

  •  Here, 120 is the style code for YYYY-MM-DD.
  • Older SQL Server Versions (Pre-2008)

 If you’re working with SQL Server 2005 or earlier, you’ll need to use string manipulation or CONVERT with styles since the DATE datatype wasn’t introduced until SQL Server 2008.

Best Practice:

  • Use CAST or CONVERT to DATE when you want the result as a true date type.
  • Use string formatting only when you need the date in a specific textual format.

In short, CAST(GETDATE() AS DATE) or CONVERT(DATE, GETDATE()) are the cleanest ways to return only the date from a DateTime value in SQL Server.



Your Answer

Interviews

Parent Categories