Tip of the Day : How to Get the Date Part of a DATETIME Data Type

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - October 14, 2024

How to Get the Date Part of a DATETIME Data Type

In SQL Server 2000 and SQL Server 2005, to get the date part of any given date of DATETIME data type you can do the following:

SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) 
AS [DateOnly]

Using the same technique, to get the first day of the month and first day of the quarter for any given date of DATETIME data type, you can do the following:

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0 ) 
AS [FirstDayOfTheMonth]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()), 0 )
AS [FirstDayOfTheQuarter]

In SQL Server 2008, to get the date part of a DATETIME data type you can also do the same thing as above or you simply need to cast it to a DATE data type:

SELECT CAST(GETDATE() AS DATE)
SELECT CAST(SYSDATETIME() AS DATE)

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions