From Month week wise calculation required

Hi ,

I have to break down the current month & year calendar in to 4 pieces (as week) and assign the integer values ( 1 to 4 ) . Is that possible ?

Any luck here … Breaking bigfix to find all the way :sob:

Your question is really ambiguous. Can you give a better description of what you’re looking for and maybe some examples of what the date might be and what you want the output to be?

Two different methods (division and modulos)

Division

(month of current date as integer - 1) / 3 + 1

Output:

Month Value
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3
10 4
11 4
12 4

Modulos

(month of current date as integer - 1) mod 4 + 1

Output:

Month Value
1 1
2 2
3 3
4 4
5 1
6 2
7 3
8 4
9 1
10 2
11 3
12 4
1 Like

Hi Strawgate ,

My requirement is

Ex : current month (March) , we have 4 weeks . I have to divide this 4 week as week 1 , week 2 , week 3 , week 4 .

week 1 , I have to mark it as 1

week 2 -------> as 2

week 3 ----------> as 3

week 4 -----------> as 4

Possible ?

Something like that?

q: if (((current day_of_month as integer) mod 7) = 0) then ((current day_of_month as integer)/7) else (((current day_of_month as integer)/7) + 1)
A: 3

Example:

q: if ((1 mod 7) = 0) then (1/7) else (1/7 + 1)
A: 1

q: if ((7 mod 7) = 0) then (7/7) else (7/7 + 1)
A: 1

q: if ((8 mod 7) = 0) then (8/7) else (8/7 + 1)
A: 2

q: if ((14 mod 7) = 0) then (14/7) else (14/7 + 1)
A: 2

q: if ((15 mod 7) = 0) then (15/7) else (15/7 + 1)
A: 3

q: if ((21 mod 7) = 0) then (21/7) else (21/7 + 1)
A: 3

q: if ((22 mod 7) = 0) then (22/7) else (22/7 + 1)
A: 4

q: if ((28 mod 7) = 0) then (28/7) else (28/7 + 1)
A: 4

q: if ((29 mod 7) = 0) then (29/7) else (29/7 + 1)
A: 5

What happens on the fifth week?

1 Like

Hi All ,

I have done something like this . Still facing some error .

(if (not exists key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” whose (exists substrings separated by “,” whose (exists (it as month) OR it as lowercase = “all”) of (value “Months” of it as string) AND exists substrings separated by “,” whose (it as integer < 5 and it as integer > 0) of (value “Week” of it as string) AND exists substrings separated by “,” whose (exists day_of_week (it)) of (value “DayAlpha” of it as string) AND conjunction of (exists time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowStart” of it as string; value “WindowEnd” of it as string)) of native registry) then “not defined” else (if (disjunction of (((it as lowercase = “all” or it as month = current month) of item 0 of it) AND (it as integer - 1 = (current day_of_month as integer - 1) / 7) of item 1 of it AND (if (item 3 of it < item 4 of it) then (day_of_week (item 2 of it) = current day_of_week AND time of current time_of_day >= (item 3 of it - 10minute) AND time of current time_of_day < item 4 of it) else ((day_of_week (item 2 of it) = current day_of_week AND time of current time_of_day >= (item 3 of it - 10minute)) OR (day_of_week (item 2 of it) + day = current day_of_week AND time of current time_of_day < item 4 of it)))) of (substrings separated by “,” whose (exists (it as month) or it as lowercase = “all”) of (value “Months” of it as string) , substrings separated by “,” whose (exists (it as integer)) of (value “Week” of it as string) , substrings separated by “,” whose (exists day_of_week (it)) of (value “DayAlpha” of it as string) , (time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowStart” of it as string) , (time_of_day ((preceding text of it & “:” & it) of last 2 of it)) of (value “WindowEnd” of it as string)) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) AND (exists (((two digit hour of it & “” & two digit minute of it) of current time_of_day) >= ((last 4 of (“0000” & ((it / 60) as string & last 2 of (“00” & ((it mod 60) as string))) of (first 2 of it as integer * 60 + last 2 of it as integer - 10) of it) of ((value “WindowStart” of it as string) of key “HKEY_LOCAL_MACHINE\SOFTWARE\CRQ\Maintenance\Reboot” of native registry) as string)))) then “yes” else “no”))

Basically I am trying to cover 2 areas.

  1. Patch week , month & year calculation based on the registry value .

  2. 10mins subtracted from “WindowStart” time in order to make sure my action is applicable & action has to start before 10mins of windowstart time .

However the server is not coming applicable list & action not started yet . Not sure where exactly the problem now .

Instead of 10minute please try 10*minute (it seems, you have 2 places like that to fix)

Interesting question. I think you are asking to break the month into 4 or 5 weeks.
2 questions on your requirement.

  • does a partial week at the start of a month count as “this month” or “last month”?
  • does your “week” start on a specific day of the week (monday start? Sunday start?)

Answer to this ,

March 4th 2019 ==> My first patch week .

March 11th 2019 ==> 2nd week etc

for the base relevance, consider this one?

q: (it, (it - first monday of month_and_year of it)/week +1) of ( March 1 of 2019 + it * day) of integers in (0,30)

To translate into a simple calculator for today, March 20, we are in week 3 (based on Monday March 4 being the start of week 1)

q: (current date - first monday of current month_and_year)/week +1
A: 3

You might note that for March 1, you get “week 0” instead of “week 4 of last month’s calendar” - I have not yet solved that edge.

Solved for the edge case for “last month’s final week”

q: ((it / week + 1) of minimum of (it - first monday of month_and_year of it;it - first monday of (month_and_year of it - month)) whose (it >= 0*day))  of (current date)
A: 3
T: 27.320 ms
I: singular integer

and the test harness to demo it in action across the days of 2019
q: (it, (it / week + 1) of minimum of (it - first monday of month_and_year of it;it - first monday of (month_and_year of it - month)) whose (it >= 0*day)) of (January 1 of 2019 + it * day) of integers in (0,365)

3 Likes

Thanks Brolly. Nice explanation.