Buena Buena - 1 year ago 148
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

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download