Hi,
My current problem at the moment is that I want to get the current date and specify which month that date is in based on a condition. The condition is that +5 days from the start of a month, the bot will consider it the previous month. For example if the current date is between 1st of March and 5th of March inclusive, it will display the message “February 2019”.
Let me know whether this suits your requirement… If it solves the problem, please mark the answer as the solution so that it will help others who are looking for similar solutions
Hi @Lahiru.Fernando,
Thanks a lot this almost solved all of my issues, but after going through the workflow I am concerned about if the date was 01/01/2019 for example. As the message box will display CurrentDate.Year.ToString, wouldn’t the output become something like December 2019?
Oh… yeah… in my solution it will display as December 2019… My bad i didnt handle that in the code.
But you can easily check that using another IF condition… same as we check the day.
In your sample date…
If date’s month is January & day is <= 5
Then CurrentDateVariable.Year.AddYear(-1)
Else
You xan display the same current year…
Its very much similar to the existing if condition
You could simplify the whole logic by using a DateTime object as your effective date DateTime effectiveDate = DateTime.Today.AddDays(-5)
And use that whenever you need to check .Month or .Year etc.
This has an added benefit of being able to test corner cases (you can mock it easily) like year changes etc. and its consistent.
Storing day, month and year in separate variables is just inviting an error to happen.
My God, you are right. This simplifies the solution a lot .
Message Box displays in that format for my usage.
In this case, all I need is the year and month so if I just -5 days from the current date, I will get the correct effective date for my usages as the day is not that important.