Buena Buena - 2 months ago 12
C# Question

How to subtract a day from a DateTime?

What is wrong here:

DateTime dateForButton = DateTime.Now;
dateForButton = dateForButton.AddDays(-1); // ERROR: un-representable DateTime

The full error message is:

The added or subtracted value results in an un-representable DateTime.

Parameter name: value


That error usually occurs when you try to subtract an interval from DateTime.MinValue or you want to add something to DateTime.MaxValue (or you try to instantiate a date outside this min-max interval). Are you sure you're not assigning MinValue somewhere?