Help me with this date logic

"Hello everyone, I have a scenario here that I’m struggling to comprehend, and I’m looking for an appropriate solution. Please examine the following text:

/*keep today -1 days, change to current month or add the previous month */

%OL(1 ,' 2Sep2023'd);

%OL(2 ,' 3Sep2023'd);

%OL(5 ,' 6Sep2023'd);

%OL(6 ,' 7Sep2023'd);

%OL(10,'11Sep2023'd);

%OL(14,'15Sep2023'd);

%OL(15,'16Sep2023'd);

%OL(16,'17Sep2023'd);

%OL(20,'21Sep2023'd);

%OL(22,'23Sep2023'd);

%OL(25,'26Sep2023'd);

Now, consider this line, for example: %OL(1 ,' 2Sep2023'd);. If the current day (only the day, not the entire date) is greater than 2Oct2023 (only the day), I need to change the month to the current month or to the previous month. For instance, if the current day is 3 or any value higher than 2, I must change the month to the current month. In this case, it will become %OL(1 ,' 2Oct2023'd);.

According to this logic, here’s the current state of the text:

%OL(1 ,' 2Oct2023'd); // Since the current day is greater than 2, I have changed the month to Oct

%OL(2 ,' 3Oct2023'd); // Since the current day is greater than 3, I have changed the month to Oct

%OL(5 ,' 6Oct2023'd); // Since the current day is greater than 6, I have changed the month to Oct

%OL(6 ,' 7Oct2023'd); // Since the current day is greater than 7, I have changed the month to Oct

%OL(10,'11Oct2023'd); // Since the current day is greater than 11, I have changed the month to Oct

%OL(14,'15Sep2023'd); // Since the current day is lower than 15, I have changed the month to Sep

%OL(15,'16Sep2023'd); // Since the current day is lower than 16, I have changed the month to Sep

%OL(16,'17Sep2023'd); // Since the current day is lower than 17, I have changed the month to Sep

%OL(20,'21Sep2023'd); // Since the current day is lower than 21, I have changed the month to Sep

%OL(22,'23Sep2023'd); // Since the current day is lower than 23, I have changed the month to Sep

%OL(25,'26Sep2023'd); // Since the current day is lower than 26, I have changed the month to Sep

In this text, everything remains fixed except the month and year ,This text is part of a larger text file, and the text file is static; I can make manual modifications on my end.

I have two solutions for the replacement:

  1. Assign each month a unique keyword, like this:
%OL(1 ,' 2<02_OL_MonthYear>'d);

%OL(2 ,' 3<03_OL_MonthYear>'d);

%OL(5 ,' 6<06_OL_Month>2023'd);

%OL(6 ,' 7<07_OL_MonthYear>'d);

%OL(10,'11<11_OL_MonthYear>'d);

%OL(14,'15<15_OL_MonthYear>'d);

%OL(15,'16<16_OL_MonthYear>'d);

%OL(16,'17<17_OL_MonthYear>'d);

%OL(20,'21<21_OL_MonthYear>'d);

%OL(22,'23<23_OL_MonthYear>'d);

%OL(25,'26<26_OL_MonthYear>'d);
  1. Prepare the entire text and add it at once using <Whole Text Keyword>.

One thing i forget to mention previously is that if the current month is januarry then if the -1 month scenrao will also change the year

For this example lets take current month Jan and Year 2023 , so in this case the text will be like this

%OL(1 ,' 2Jan2023'd);

%OL(2 ,' 3Jan2023'd);

%OL(5 ,' 6Jan2023'd);

%OL(6 ,' 7Jan2023'd);

%OL(10,'11Jan2023'd);

%OL(14,'15Dec2022'd);

%OL(15,'16Dec2022'd);

%OL(16,'17Dec2022'd);

%OL(20,'21Dec2022'd);

%OL(22,'23Dec2022'd);

%OL(25,'26Dec2022'd);

Hello @indiedev91

Assign activity:
To: updatedLine (String)
Value:
String.Format(“%OL({0} ,‘{1:d}d’);”,
line.Split(","c)(0).Trim(),
If(DateTime.Now.Day > Convert.ToInt32(Regex.Match(line, “,’ (\d+)\w+\d+”).Groups(1).Value),
DateTime.Now.AddMonths(1),
DateTime.Now))

Thanks & Cheers!!!

Okay i figured it out in this way , please have a look at the solution

OlDateLogic.zip (3.4 KB)

1 Like

Thanks for the answer , but this seems a little complicated for me at first , so i used my solution instead

1 Like

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