Transact SQL 101 - Lesson 07_04_SQL.txt

(0 KB) Pobierz
--Date and Time Functions
--Example 1
--DAY/MONTH/YEAR
--Returns an integer representing the day, month or year part of the specified date.
SELECT DAY(GETDATE())
SELECT DAY('8/25/2007')

SELECT MONTH(GETDATE())
SELECT MONTH('6/10/2007')

SELECT YEAR(GETDATE())
SELECT YEAR('8/25/2007')

--Example 2
--DATEPART ( datepart , date )
--Returns an integer that represents the specified datepart of the specified date.
SELECT DATEPART (month, '6/10/2007')
SELECT DATEPART (m, '6/10/2007')
SELECT DATEPART (dy, GETDATE())

--Example 3
--DATENAME ( datepart ,date )
--Returns a character string representing the specified datepart of the specified date
SELECT DATENAME(month, '1/1/2008')
SELECT DATENAME(dw, GETDATE())
Zgłoś jeśli naruszono regulamin