Collections:
Getting Parts of DATETIME Values as Integers in SQL Server
How To Get Parts of DATETIME Values as Integers in SQL Server Transact-SQL?
✍: FYIcenter.com
Sometimes, you want to one specific part of a DATETIME value as an integer to be used in your own date and time calculations. This can be done by using the DATEPART() function in the following format:
DATENAME(datepart, date) returns INT: "date" - the input date "datepart" - one of predefined date part names See other tutorials for the list of names
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),DATEPART(year, @birth_date)) + '.' + CONVERT(VARCHAR(10),DATEPART(month, @birth_date)) + '.' + CONVERT(VARCHAR(10),DATEPART(day, @birth_date)); GO You were born on 1987.5.19
⇒ Getting Year, Month and Day Out of DATETIME Values in SQL Server
⇐ Getting Month and Weekday Names from DATATIME Values in SQL Server
⇑ Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-14, 2406🔥, 0💬
Popular Posts:
What Is an Oracle Instance in Oracle? Every running Oracle database is associated with an Oracle ins...
How To Verify Your PHP Installation in MySQL? PHP provides two execution interfaces: Command Line In...
Where to find answers to frequently asked questions on Storage Engines: MyISAM, InnoDB and BDB in My...
How To Count Rows with the COUNT(*) Function in SQL Server? If you want to count the number of rows,...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...