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
Â
⇒Date/Time Operations and Functions in SQL Server Transact-SQL
2017-02-14, 1165👍, 0💬
Popular Posts:
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...
What Is ISAM in MySQL? ISAM (Indexed Sequential Access Method) was developed by IBM to store and ret...
How To Recreate an Existing Index in SQL Server? If you want to change the definition of an existing...
Where to find MySQL database server tutorials? Here is a collection of tutorials, tips and FAQs for ...
How to connect SQL Server Management Studio Express to SQL Server 2005 Express in SQL Server? Once y...