Calculate Previous Monday As A Date

mcandrewe

Member
Hi All,
I need to select a file whereby the file name will reference last Monday and last Sunday in the filename.
So For example today is 03/08/2018. The file my process would need to select would include the dates 23/07/2018 and 30/07/2018.

I have tried to use calendar objects and such but can't seem to find anything. I have also tried using blocks of C# but get errors in BP. Any help would be greatly appreciated.

Regards
 

VJR

Well-Known Member
Hi mcandrewe,

Below is the Visual Basic equivalent which can be converted to C#.

PrevMondayDate is an output parameter from the code stage of type Date

Code:
Dim WeekdayNum as Integer

WeekdayNum = Weekday(Today.AddDays(-1),FirstDayOfWeek.Monday) 
PrevMondayDate = DateTime.Today.AddDays(-WeekdayNum)

The above can be written in a single line as follows-

Code:
PrevMondayDate = DateTime.Today.AddDays(-Weekday(Today.AddDays(-1),FirstDayOfWeek.Monday))

View attachment 1533371348777.png
 

mcandrewe

Member
Hi mcandrewe,

Below is the Visual Basic equivalent which can be converted to C#.

PrevMondayDate is an output parameter from the code stage of type Date

Code:
Dim WeekdayNum as Integer

WeekdayNum = Weekday(Today.AddDays(-1),FirstDayOfWeek.Monday)
PrevMondayDate = DateTime.Today.AddDays(-WeekdayNum)

The above can be written in a single line as follows-

Code:
PrevMondayDate = DateTime.Today.AddDays(-Weekday(Today.AddDays(-1),FirstDayOfWeek.Monday))

View attachment 1565



Thanks VJ,
However, I am getting an error. I tried adding the ; but that lead to further errors. Any idea what is causing this?
 

Attachments

  • Code Error.PNG
    22.2 KB · Views: 85

VJR

Well-Known Member
Hi mcandrewe,

The code that I have provided you is a Visual Basic one. It looks like you are using C# as the language and hence showing an ";" expected error.
Either you will need to change the language to VB or convert the above code to its C# equivalent.
 
Top