Sunday, April 1, 2012
New date/time functions in SQL 2012
So I was just doing a little reading on some new features in SQL 2012 and the new temporal functions sparked my imagination. I can't count how many times I've wanted an easy way to be able to do something like find the first of the month given only the year and month number. Usually, you jump through some hoops to do that in any version up to and including SQL 2008R2. But now, it seems that they've added a family of functions that let you pass in each date part as an argument and it spits out the appropriate data type. Going back to the first of the month example, one can now write "select datefromparts(year, month, 1) from table" and it'll spit out result set with the given firsts of the month. Sometimes, it's the little things.