Returns an International Organization for Standardization (ISO) compatible week number for any date since 1900.


Each week can have a number between 1 and 53 depending upon the year.  Week 1 of each year begins on the first week of a new calendar year where the first Thursday in January occurs.  This means that any week where 1-January falls on a Monday, Tuesday, Wednesday or a Thursday, that week is Week 1.  When 1 January falls on a Friday, Saturday, or a Sunday, that week is either week 52 or week 53.



WeekNumber = WeekNumberISO( Expression )





Any expression that resolves to a date in the format YYYYMMDD.



The week number for any date since 1900



'   ---------------------------

'   WeekNumber - ISO Compatible

'   ---------------------------

'   ISO says to find the first Thursday of each year and then back

'   off to that Week's Monday to determine the first date in a year

'   when Week #1 occurs.


'   This code uses that same logic to find the first Thursday and then

'   goes back to identify that week's Monday.


'   When the first date of a year doesn't fall into Week #1, it says

'   to use information from the previous year to determine if the first

'   date of the year falls into Week #52 or Week #53.  This code also

'   uses that logic to fill that requirement.

'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Variables: WeekNumber TYPE: INTEGER  

  Variables: Day_Offset TYPE: INTEGER

  Variables: DayName TYPE: STRING


  Day_Offset = 0


  WeekNumber = WeekNumberISO(Instrument.Date[Day_Offset])


  '   ``````````````````````````````````````````````````````````    


  '   ``````````````````````````````````````````````````````````

  '   Print the Results to the Output.CSV File

  '   ``````````````````````````````````````````````````````````


  If Instrument.CurrentBar = 1 Then

    '   Send Results to the PRINT LOG  

    Print "Date: ",  _

          "  DOW-Name ", _

          "   Week_# "            



  DayName = DayOfWeekName( DayOfWeek(Instrument.Date[Day_Offset]))


  '   Send Results to the PRINT LOG  

  Print Instrument.Date[Day_Offset], _

        DayName, _


'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




See Also:

Date Time Functions


Edit Time: 4/9/2018 9:34:34 AM

Topic ID#: 647


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software