DATE (Scalar Function)
Overview
The DATE
scalar function extracts the date part of a datetime
, datetime2
, smalldatetime
, or datetimeoffset
expression, discarding the time component.
Syntax
DATE ( expression )
Parameters
expression
– An expression of a date/time data type.
Return Type
Returns a value of type date
.
Examples
Basic usage
SELECT DATE('2024-08-15 13:45:30') AS OnlyDate;
Result:
OnlyDate
------------
2024-08-15
Using DATE with a table
CREATE TABLE Orders
(
OrderID int,
OrderDate datetime
);
INSERT INTO Orders VALUES (1, '2025-01-10 09:15:00'), (2, '2025-02-20 14:30:45');
SELECT OrderID,
DATE(OrderDate) AS OrderDateOnly
FROM Orders;
Result:
OrderID | OrderDateOnly
--------+--------------
1 | 2025-01-10
2 | 2025-02-20