Date get based on fixed week

Hi Team

How do we get current week number . Remember first Saturday of year is considered as first day of the year.

Thanks in advance

Hi @SuperWomen

Please use the below syntax:

Enumerable.Range(0,Now.DayOfYear).Count(Function(i) New DateTime(Now.Year,1,1).AddDays(i).DayOfWeek = DayOfWeek.Saturday)

Regards
PS Parvathy

2 Likes

Hi,

How about the following expression? Try and let me know if it helps

Enumerable.Range(0,Now.DayOfYear).Count(Function(i) New DateTime(Now.Year,1,1).AddDays(i).DayOfWeek = DayOfWeek.Saturday)

Cheers,

2 Likes

Hi @SuperWomen

  1. Assign
    today = Now.Date
    yearStart = New DateTime(today.Year, 1, 1)
  2. Assign (find first Saturday)
    firstSaturday = yearStart
    While firstSaturday.DayOfWeek <> DayOfWeek.Saturday
    firstSaturday = firstSaturday.AddDays(1)
  3. If condition
    If today < firstSaturday
    weekNumber = 1
    Else
    daysDiff = (today - firstSaturday).Days
    weekNumber = (daysDiff \ 7) + 1

This way the week count always starts from the first Saturday of the year.

Hi @SuperWomen ,

Try this:
CInt(Math.Floor((Now - firstSaturday).TotalDays / 7)) + 1

Let me know if u need help
Thanks & Happy Automations.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.