Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

get month from date sql server

----SQL Server
--Setup
CREATE TABLE Users
    ([name] varchar(100), [creationDate] datetime)
;
INSERT INTO Users
    ([name], [creationDate])
VALUES
    ('Alice', CAST('2021-12-31T12:34:56' AS DATETIME)),
    ('Bob', GETDATE())
;

--Get month
SELECT DATEPART(MM, u.creationDate)
FROM Users u
Source by www.sqltutorial.org #
 
PREVIOUS NEXT
Tagged: #month #date #sql #server
ADD COMMENT
Topic
Name
7+8 =