I have the following code in my C# program.
DateTime dateForButton = DateTime.Now; dateForButton = dateForButton.AddDays(-1); // ERROR: un-representable Date
The object (i.e. destination variable) for the AddDays method can't be the same as the source.
Instead of:
DateTime today = DateTime.Today; today.AddDays(-7);
Try this instead:
DateTime today = DateTime.Today; DateTime sevenDaysEarlier = today.AddDays(-7);