Date calculation to work out financial week number

Comments

7 comments

  • Rainer Grabowski

    Hi Nicole,

    Is July 1st always week #1 or can it be #52 (like in this year; July 1st is calendar week #26 - which # is financial week: 1 or 52?)

    This would give you July 1st, 2016 = # 52:

    var date = @Date A;
    var dateY = moment(date).year();
    var dateW = moment(date).isoWeek();
    var finStart = moment(dateY +"-07-01","YYYY-MM-DD");
    var finStartW = moment(finStart).isoWeek()
    dateW < finStartW ? dateW+finStartW : dateW == finStartW ? dateW+26 : dateW-finStartW

    And this July 1st , 2016 = financial week # 1

    dateW < finStartW ? dateW+finStartW : dateW == finStartW ? dateW+26 : dateW-finStartW


    Rainer
    rg@delos-consulting.com

     

     

    0
    Comment actions Permalink
  • Nicole Atkinson

    Hi Rainer,

    Thanks for your help on this one I will test it out shortly we start week #1 on the calendar week #26 so will try it out and let you know.

    Thank you again.

    0
    Comment actions Permalink
  • Nicole Atkinson

    Hi Rainer,

    That looks to be working except that I can't see where the change is to make July 1st , 2016 = financial week # 1

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Nicole, 

    so July, 1st (a Friday this year) would be # 1 (2016/2017) and Jun, 30th (Thursday) # 52 (2015/2016)?

    0
    Comment actions Permalink
  • Nicole Atkinson

    Hi,

    Week #1 (2017) for us would start Sunday 26th June and end Saturday 2nd July.

    Week #52 (2016) is Sunday 19th June - Saturday 25th June.

     

    thanks

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Nicole,

    I've thought financial weeks in Australia follow the isoweek specifications, but it seems, they don't.

    So this would give you the right result for:
    Week #1 (2017) = Sunday 26th June - Saturday 2nd July.
    Week #52 (2016) = Sunday 19th June - Saturday 25th June.

    var date = @Date A;
    var dateW = moment(date).week();
    dateW <= 26 ? dateW+26 : dateW - 26

    But for the next FY you'll get this:
    Week #1 (2018) = Sunday 2nd July - Saturday 8th July
    Week #52 (2017) = Sunday 25th June - Saturday 1st July.
    If this is right you can use it. If the wanted result should be
    Week #1 (2018)  = Sunday 25th June - Saturday 1st July
    Week #51 (2017) = Sunday 18th June - Saturday 24th June
    you can use this:

    var date = @Date A;
    var dateY = moment(date).year();
    var dateW = moment(date).week();
    var finStart = moment(dateY +"-07-01","YYYY-MM-DD");
    var finStartW = moment(finStart).week();
    +(dateW == "26" && finStartW == "26") || +(dateW == "27" && finStartW == "27") ? 1 : dateW <= 26 ? dateW+26 : dateW - 25

    Rainer

     

    0
    Comment actions Permalink
  • Nicole Atkinson

    Thank you I think that has done it. Appreciate your help on this one.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk