DateTime: How to find Previous Week Date

Hey All!

Quick question… I have a process that runs once a week over night with both a Dispatcher and Performer. The dispatcher navigates to a website, generates and downloads a report based on dates. Since the process runs once a week, I’m setting the From Date as “DateTime.Now.AddDays(-6).ToShortDateString” and the To Date as “DateTime.Now.ToShortDateString” (Tuesday - Monday).

Every so often the process needs to be re-ran on Tuesday due to an error on the application side. This shits the dates by one day (Wednesday - Tuesday) which can create a problem for the following run as Tuesdays transactions can be processed twice.

Anyone have any insight into how to find the date of last week Tuesday and this week Monday?


Got it!

Assign DaysFromMonday to ((DayOfWeek.Monday) - (DateTime.Now.DayOfWeek))
For Last Tuesday - DateTime.Now.AddDays(DaysFromMonday - 6).ToShortDateString
For Monday - (DateTime.Now.AddDays(DaysFromMonday).ToShortDateString)


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