Skip to main content
July 21, 2010
Question

Week Function gives wrong week of year.

  • July 21, 2010
  • 2 replies
  • 1751 views

Hi all,

I just figured out the week function is adding a week to the actual week of year.

A date of 2010-07-21 returns a week of 30 not 29. And ideas??

This a Windows 2003 server running Coldfusion MX 7

Many thanks for the help.

Brian

    This topic has been closed for replies.

    2 replies

    Inspiring
    July 21, 2010

    It might be time to upgrade CF.  I just ran a test on CF8, and both week() and datePart() return 29 for the week number for 21/7/2010.

    --

    Adam

    Inspiring
    July 21, 2010

    So, January 1 was a Friday, right?  Here's what my data warehouse thinks about that.

    select datepart(week, '20100102') from u_one; -- Saturday

              1
    select datepart(week, '20100103') from u_one;  -- Sunday

              2

    select datepart(week, current_date) from u_one;

             30

    Inspiring
    July 21, 2010

    Dan Bracuk wrote:

    So, January 1 was a Friday, right?  Here's what my data warehouse thinks about that.

    select datepart(week, '20100102') from u_one; -- Saturday

              1
    select datepart(week, '20100103') from u_one;  -- Sunday

              2

    select datepart(week, current_date) from u_one;

             30

    A system conforming to ISO 8601 would disagree there.  Firstly, weeks start on a Mon as far as these things go (obviously human calendars vary by country, standards-adhering ones do not), so both of those should be the same week.

    Also, Week 1 is the week that has the first Thursday of the year in it, so Week 1 doesn't start until the Monday after your test dates.  Those dates are in week 53 from the previous year.

    CF (well: CF8, anyhow) seems to conform to ISO 8601.  CFMX7... seemingly not so much.

    Ref: http://en.wikipedia.org/wiki/ISO_week_date

    --
    Adam

    Inspiring
    July 21, 2010

    Why is 30 incorrect? Jan 1, 2010 is included in week 1. You count from there till July 21, 2010 and you'll get week 30.