January 21, 2013 at 5:31 am
Sean Pearce (1/21/2013)
Stewart "Arturius" Campbell (1/21/2013)
Good qurstion, Ron,Thanks
Sean Pearce (1/21/2013)
This question is better suited for http://www.GeographyCentral.com.How does knowing the last day of February in 2016 have anything to do with SQL Server? I had to check a calendar in order to answer this question, books online was no good here.
Point of note:
The EOMONTH function in Excel currently does not recognise leap years. Therefore, if this was an exact copy of the function as used in Excel, it would not work correctly.
Since when did SQL Server start copying Excel?
The link you provided says that this was only a problem for century years not divisible by 400 (so 1900, 2100 etc.) So the Excel formula would have given the correct answer to this question. It also says that the error was fixed in Excel 2000.
January 21, 2013 at 7:41 am
I'd never heard of this function, so it was good to hear and learn about it. I have never of this function (not even in Excel since I don't use it that much), so much like Koen and Tom I went into this under the impression that they hadn't screwed up a new function to use.
Thank you very much for the great question on a new 2012 feature.
January 21, 2013 at 7:44 am
Had not heard about this function until now. Like others I assumed they got it right. The question actually pretty much answers itself. The first 3 sets of choices are all pretty much the same thing. If the function got the leap year right or wrong will provide those. The last couple options seemed like a no brainer to me because the implicit date conversion would not be any different in a function than anywhere else and if the conversion had failed none of the rest of the answers would have even been possible. Given that, there were 8 choices and we were told there were 4 possible answers it all came down to a coin-toss...does the function correctly recognize leap years or not.
Good question and it is great to learn about new stuff in 2012!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 21, 2013 at 7:52 am
Hugo Kornelis (1/21/2013)
... But in SQL Server 2012, there are definitely a lot of new function that are totally useless - except if you want to enable an easier transition from VBA and Access SQL to T-SQL. EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.
I take a different view of Eomonth: anything that makes the developer's life easier is a useful function. It is a lot easier to write EOMONTH(somedate)
for example than to write cast(DATEADD(DAY,-DATEPART(DAY,somedate),DATEADD(MONTH,1,somedate)) AS DATE).
A developer is unlikely to get an EOMONTH call wrong, and you can't say the same for a construction of the same function from datepart and dateadd. It's also a lot easier to read the Eomonth call, to see instantly what it means, and hence to debug and maintain and enhance - so there is a lot of real business value in that function.
It would have saved me some pain if my people could have used something like EOMONTH back in the days of SQL Server 2000. And since we were a shop where the scripting language was JScript not VBA that wasn't because people were converting anything which already used an EOMONTH function.
Maybe some of the other functions are a bit useless, though.
Tom
January 21, 2013 at 8:18 am
L' Eomot Inversé (1/21/2013)
Hugo Kornelis (1/21/2013)
... But in SQL Server 2012, there are definitely a lot of new function that are totally useless - except if you want to enable an easier transition from VBA and Access SQL to T-SQL. EOMONTH is one of them, IIF is a very clear example, and I think there were a few more, but I don't have the time to hunt them all down now.I take a different view of Eomonth: anything that makes the developer's life easier is a useful function. It is a lot easier to write EOMONTH(somedate)
for example than to write cast(DATEADD(DAY,-DATEPART(DAY,somedate),DATEADD(MONTH,1,somedate)) AS DATE).
A developer is unlikely to get an EOMONTH call wrong, and you can't say the same for a construction of the same function from datepart and dateadd. It's also a lot easier to read the Eomonth call, to see instantly what it means, and hence to debug and maintain and enhance - so there is a lot of real business value in that function.
It would have saved me some pain if my people could have used something like EOMONTH back in the days of SQL Server 2000. And since we were a shop where the scripting language was JScript not VBA that wasn't because people were converting anything which already used an EOMONTH function.
Maybe some of the other functions are a bit useless, though.
My main issue with EOMONTH is that it's a lost opportunity to do something *really* useful, and a whole bunch of future forum questions.
It's just too compelling to write "WHERE MyDateColumn BETWEEN *something to calculate the first day of the current month* AND EOMONTH(getdate())" - but that would in many cases not return the correct results. EOMONTH always returns the last day of the month with time 0:00, so if my data stores time as well, I lose all events on the last day. For regular datetime data, I would want a function to return 23:59:59.997; for smalldatetime 23:59; for datetime2(7) 23:59:59.9999999, and for my specific data that is constrained to store only whole hours I want 23:00.
So for me, a far better choice would have been to implement a BOMONTH (for the first day of the month - though one can wonder how much this simplifies life, as the first of the month is pretty easy to get anyway) and then use a DATEDIFF to subtract 3ms, 1 second, 100 ns, or an hour.
January 21, 2013 at 12:05 pm
Ron, as always I love your question. Please keep them comin'!
January 21, 2013 at 1:14 pm
Revenant (1/21/2013)
Ron, as always I love your question. Please keep them comin'!
Thank you .. coming from one as knowledgable as you about sql ... it is an honor
January 21, 2013 at 10:04 pm
Even though i got idea about the function from BOL, I don't want to sit and calculate what will be the last day of 2016 or last day of february 2016.
So I created an UDF to do the work of EOMONTH() and excuted the script to find the answer of QotD.
I thank Ron for introducing this new function to most of us..
--
Dineshbabu
Desire to learn new things..
January 22, 2013 at 4:16 am
Thank you for the question.
February 19, 2013 at 10:51 pm
I still don't get why people when talking about Dates include a Time Component. Dates are Dates and Time is Time. We have had Date & Time Data Types for many years now but it seems SQL Server folk love their datetime and all of the Arcane knowledge required to use it.
Personally I'd like to see datetime deprecated so that we're left with Date, Time & DateTime2.
I'm interested to know who is still using datetime when all that they really want is Date.
End of Rant.
David
February 22, 2013 at 1:47 am
get 1 point without running the code
but last day of 2016 is pure chance !
Viewing 11 posts - 16 through 25 (of 25 total)
You must be logged in to reply to this topic. Login to reply