Yes there is a Week 53

Yes there is actually a week 53, it's called a leap week, and happens approximately 71 times in 400 years. More specifically it happens whenever December 31/January 1st land on a Thursday, and a bunch of other cases. It's all part of the ISO 8601 standard. Meaning today is actually the first week of the year. Not a big surprise to anyone I would say or?

Then why was the report not showing the right information?

Who is out of Sync

I've tested this in Adobe ColdFusion as well as in Railo and both engines return the week date of todays date as week 1. Looking at my Moleskine it's also showing week 1, Google Calendar is also showing week 1, php is showing week 1, all good so far I would say.

I then decided to take a look at a couple of databases, specifically MSSQL and MySQL here I was rather surprised to see that only MSSQL in produced a week of 2 for todays date, MySQL produced a 1.

So who is wrong and who is right? I guess it depends on whether ISO 8601 is being followed or not. MySQL implements, that either Monday or Sunday is the beginning of a week, therefore since the year changes in the middle of the week. the first few days of the new year belong to week 53. This would mean that the first Monday/Sunday start the first week in the new Year.

Looking at the documentation for MSSQL Datepart I see the following:

The week (wk, ww) datepart reflects changes made to SET DATEFIRST. January 1 of any year defines the starting number for the week datepart...

Wait a sec thats not ISO 8601! They just decided that if January 1 lands on any day other than the starting day (monday/sunday) that its week 1.

So while "everyone" else is returning a week number of 1 for todays date, MSSQL is returning week 2!

When writing code that works with week numbers be aware of this discrepancy, if you haven't already come up against this before.

Happy Coding ...

4 Comments to "Yes there is a Week 53"- Add Yours
Gary Funk's Gravatar At the .gov I work at, our year started on December 26, 2009. Our months start on the first Saturday after the last Friday of the previous month. No wonder Congress is so screwed up. They can't read a calendar.
# Posted By Gary Funk | 1/4/10 1:51 AM
todd sharp's Gravatar I have a report on one of my sites that charts data out by week and I had noticed the 'Week 53' (via MySQL) in my chart last week. I never had a chance to look into it, so thanks for the explanation!
# Posted By todd sharp | 1/4/10 3:01 AM
Gary Gilbert's Gravatar What I find interesting in checking this out is that I only see a discrepancy in week 53/1 from Microsoft SQL Server which has a 3 day week 1 that goes from January 1st to Jan 3rd, and week 2 starts on Jan 4th Monday!

There was actually some confusion as to who was at fault, CF or MSSQL, after my research I can definitely say that this is a "problem" with MSSQL!
# Posted By Gary Gilbert | 1/5/10 10:13 AM
alex's Gravatar spot on! this just happened to me this week... lol
# Posted By alex | 1/7/10 9:31 PM

Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.

Tags

adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript max2007 max2008 misc open source programming railo software technology ui

Recent Entries

Converting structkeys to lowercase

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List