Collections:
Getting Year, Month and Day Out of DATETIME Values in SQL Server
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL?
✍: FYIcenter.com
You can use DATEPART() to get any part of the DATETIME value. But to get year, month and day, you can use 3 specific functions: YEAR(), MONTH() and DAY(). These functions are equivalent to DATEPART() as:
YEAR(date) = DATENAME(year, date) MONTH(date) = DATENAME(month, date) DAY(date) = DATENAME(day, date)
In following tutorial example shows you how display a birth date in a format of yyyy.m.d:
DECLARE @birth_date DATETIME; SET @birth_date = '1987-05-19 16:10:41.403'; SELECT 'You were born on ' + CONVERT(VARCHAR(10),YEAR(@birth_date)) + '.' + CONVERT(VARCHAR(10),MONTH(@birth_date)) + '.' + CONVERT(VARCHAR(10),DAY(@birth_date)); GO You were born on 1987.5.19
Â
⇒Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-14, 3160🔥, 0💬
Popular Posts:
How to download and install Microsoft .NET Framework Version 2.0 in SQL Server? .NET Framework Versi...
Where to find MySQL database server tutorials? Here is a collection of tutorials, tips and FAQs for ...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
How To Set Up SQL*Plus Output Format in Oracle? If you want to practice SQL statements with SQL*Plus...
How To Convert Characters to Numbers in Oracle? You can convert characters to numbers by using the T...