I have the following code in my C# program.
DateTime dateForButton = DateTime.Now; dateForButton = dateForButton.AddDays(-1); // ERROR: un-representable Date
The dateTime.AddDays(-1) does not subtract that one day from the dateTime reference. It will return a new instance, with that one day subtracted from the original reference.
dateTime.AddDays(-1)
dateTime
DateTime dateTime = DateTime.Now; DateTime otherDateTime = dateTime.AddDays(-1);