I want to retrieve today’s data based on the date in the file title. but when it’s Monday, I want to retrieve data on Saturday. what is the right code for me to write in the task? Thank You
Hi @wsinten ,
You can try
1.get yesterday
now.AddDays(-1).ToShortDateString.Replace(“/”,“.”)
or
now.AddDays(-1).ToString(“dd.MM.yyyy”)
2.check today is Monday → get last Saturday
if
Now.DayOfWeek.Equals(“Monday”)
get last saturday
datetime.now.AddDays(6 -datetime.now.DayOfWeek - 7)
Regards,
LNV
can this be used in one activity assign?
yes, this can assign as String
Assign Activity
myDateNew | DateTime =
MyDateTimeVar.AddDays(new Double(){0,-1,0,0,0,0,0}(MyDateTimeVar.DayOfWeek)).Date
within the array we can configure the specific offset for all weekdays
For saturday we do use -2
check today is Monday → get last Saturday
if
Now.DayOfWeek.Equals(“Monday”)
get last saturday
datetime.now.AddDays(6 -datetime.now.DayOfWeek - 7)
still not right. he still takes the same date as today
Assign activity:
To: fileName
Value:
If DateTime.Now.DayOfWeek = DayOfWeek.Monday Then
fileName = “YourFilePrefix_” & DateTime.Now.AddDays(-2).ToString(“ddMMyy”) & “.csv”
Else
fileName = “YourFilePrefix_” & DateTime.Now.ToString(“ddMMyy”) & “.csv”
End If
Read CSV activity:
File Path: fileName
Hi @wsinten
Please try this
currentDate = DateTime.Now.Date
If currentDate.DayOfWeek = DayOfWeek.Monday
Then
targetDate = currentDate.AddDays(-2)
Else
targetDate = currentDate
Assign fileName = "data_" + targetDate.ToString("yyyyMMdd") + ".csv"
I hope it helps!!