AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL DATEPART Function |
|
SQL > SQL Date Functions >
Datepart Function
DATEPART is a SQL Server function that extracts a specific part of the date/time value. DATEPART(part_of_day, expression) returns an integer representing the specified component — such as year, month, day, or day-of-year — from a date or datetime value in SQL Server.
SyntaxThe syntax for the DATEPART function is as follows: where part_of_day can have the following:
ExamplesExample 1The SQL statement, produces the following result: 2000
Example 2The SQL statement, produces the following result: 41
2000-02-10 is the 41st day in the year 2000. List of SQL Date Functions
Frequently Asked QuestionsWhat does the SQL DATEPART function do?DATEPART extracts a specific component of a date or datetime value in SQL Server and returns it as an integer. Components include year, quarter, month, day, hour, minute, second, day-of-year, week, and more. What is the syntax for DATEPART?
What is the equivalent of DATEPART in other databases?In Oracle and PostgreSQL, the EXTRACT function serves a similar purpose. MySQL supports both EXTRACT and dedicated functions like YEAR(), MONTH(), and DAY() for extracting date components. What integer does DATEPART(dy, '2000-02-10') return?It returns 41 — because February 10, 2000 is the 41st day of the year 2000. |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.