The SQL YEAR function evaluates the input date and returns the year
Introduction to SQL Server’s Date Functions
SQL server’s date functions provide you a set of function that you can use to manipulate dates. The function are used for a wide variety of operation such as adding weeks to a date, calculating the difference between two dates, or to decompose a date into its fundamental parts.
If you not familiar with SQL functions, then I would recommend staring with the Introduction to SQL Server Built-In Functions.
To get the most of this and our other lessons be sure to practice using the examples!
There are over twenty five different functions categorized as date functions in SQL server.
All of the functions are listed on the Date Functions (Transact-SQL) page. I would recommend visiting that page to learn about each function.
Rather than reiterate that material, we’ll focus on the functions I’ve seen in commonly used in business.
In the following tables I categorized the functions and color coded them. The color code corresponds to the likely hood you would use that particular function in a business environment. Green are most likely to be used, and red less.
This isn’t a strict scale, and all functions have a use in some business case, but I wanted a way to help you winnow down the field to those most relevant.
Here is my attempt:
The SQL DATEPART function returns the specified part of the input date. Description The SQL DATEPART function returns an integer value that
The SQL GETDATE function returns the current timestamp of the database as a datetime value. Description The current timestamp derives from the
Use SQL DATEADD to add days, weeks, months, or any timespan specified by datepart to a date to get another. The function
The SQL DATEDIFF function calculates and returns the difference between two date values. The value returned is an integer. You can use
When working with SQL dates, sometimes you need to calculate the end of the month. Months are tricky! Some are 28 days,