![]() I don't know of a way to make DATEPART(WEEK pretend it is DATEPART(ISO_WEEK - I think you will have to change the code (and if you are using source control, this shouldn't be very hard - how many places are you performing this calculation? Have you thought about computing it somewhere so your code doesn't have to be riddled with it? Since you're changing the code now, this might be the time to consider this.).Īnd if you really want the answer to why? I think you'll have to grab some of the original developers to determine why they chose the default that they did. ![]() The easy part is getting the ISO week number from a datetime. For example, notice the difference between the Gregorian and ISO 8601 calendars for the end of 2015: Weeks 52 & 1 become 52 & 53. They later added ISO_WEEK (2008 I believe) because the workaround in the meantime was to write your own, slow, crappy scalar UDF - in fact they even created a really bad one and put it in the official documentation (it has since been removed as far as I can tell). (Friday) is in 2015-W53, first date (Monday) is. I don't think there was really much consciousness about it, except to align to the most common standard at the time - remember this was at a time where conforming to the standards was not a top priority (else we'd not have things like timestamp, IDENTITY and TOP). ![]() ![]() Back when SQL Server first implemented the WEEK date/part, they had to make a choice. Some assumes first day of the week starts the first week but the most common idea is that the first week which has the first Thursday is the first week of the year. ISOWEEK : Returns the ISO 8601 week number of the dateexpression. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |