I have method which expects two datetime parameters
public void SomeReport(DateTime TimeFrom, DateTime TimeTo) { // ommited TimeFrom.ToString("ddMMyy"), TimeTo.ToString("ddMMyy"))); // ommited }
When I'm sending this params
DateTime TimeTo = DateTime.Now; DateTime TimeFrom = new DateTime().AddHours(-1);
This error occured:
System.ArgumentOutOfRangeException : The added or subtracted value results in an un-representable DateTime.
What can be the problem?
new DateTime()
is 01/01/0001 00:00:00
which is also DateTime.MinValue
.
You are subtracting one hour from that.
Guessing you are trying to subtract an hour from the TimeTo
value:
var TimeFrom = TimeTo.AddHours(-1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With