New functions that make datetime
variables easier to handle are always welcome. With SQL Server 2012 there are a number of new functions that we think will really make your programming life much easier. We will explore a number of examples so you can quickly understand how to use them in your everydy code.
Firstly we will start with the end of month function or, more specifically, EOMONTH, as you will soon learn. This function does exactly what it says, returning the last day of the month you specify. This will no doubt come as a pleasant addition to anyone who runs financial calculations. The syntax is as follows:
DECLARE @MyDate datetime SET @MyDate = '05/17/2012' SELECT EOMONTH (@MyDate) AS LastDayOfTheMonth
As you can see from the following result this returns the last day of the month of May:
We have written this book in a leap year which, as you know, generally only happens every four years, coinciding with the Olympics. This function removes the need to code...