Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

un-representable DateTime

Tags:

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?

like image 784
user1765862 Avatar asked Dec 04 '12 10:12

user1765862


1 Answers

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); 
like image 161
Oded Avatar answered Sep 20 '22 18:09

Oded