Example
Return the day of the month for a date:
SELECT DAY('2017/08/25') AS DayOfMonth;
Definition and Usage
The DAY() function returns the day of the month (from 1 to 31) for a specified date.
Syntax
DAY(date)
Return the day of the month for a date:
SELECT DAY('2017/08/25') AS DayOfMonth;
The DAY() function returns the day of the month (from 1 to 31) for a specified date.
DAY(date)
Return a specified part of a date:
SELECT DATEPART(year, '2017/08/25') AS DatePartInt;
The DATEPART() function returns a specified part of a date.
This function returns the result as an integer value.
DATEPART(interval, date)
Return a specified part of a date:
SELECT DATENAME(year, '2017/08/25') AS DatePartString;
The DATENAME() function returns a specified part of a date.
This function returns the result as a string value.
DATENAME(interval, date)
Return a date from its parts:
SELECT DATEFROMPARTS(2018, 10, 31) AS DateFromParts;
The DATEFROMPARTS() function returns a date from the specified parts (year, month, and day values).
DATEFROMPARTS(year, month, day)
Return the difference between two date values, in years:
SELECT DATEDIFF(year, '2017/08/25', '2011/08/25') AS DateDiff;
The DATEDIFF() function returns the difference between two dates, as an integer.
DATEDIFF(interval, date1, date2)
Add one year to a date, then return the date:
SELECT DATEADD(year, 1, '2017/08/25') AS DateAdd;
The DATEADD() function adds a time/date interval to a date and then returns the date.
DATEADD(interval, number, date)
Return the current date and time:
SELECT CURRENT_TIMESTAMP;
The CURRENT_TIMESTAMP function returns the current date and time, in a ‘YYYY-MM-DD hh:mm:ss.mmm’ format.
Tip: Also look at the GETDATE() function. Continue reading SQL CURRENT_TIMESTAMP Function
Return the tangent of a number:
SELECT TAN(1.75);
The TAN() function returns the tangent of a number.
TAN(number)
Return the sum of the “Quantity” field in the “OrderDetails” table:
SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;
The SUM() function calculates the sum of a set of values.
Note: NULL values are ignored.
SUM(expression)
Return the square of a number:
SELECT SQUARE(64);
The SQUARE() function returns the square of a number.
SQUARE(number)