un-representable DateTime

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);

new DateTime() returns the minimum representable DateTime; adding -1 hours to this results in a DateTime that can't be represented.

You probably want DateTime TimeFrom = TimeTo.AddHours(-1);


DateTime TimeTo = DateTime.Now;
DateTime TimeFrom = TimeTo.AddHours(-1);

creating a DateTime with new DateTime() gives you a DateTime with DateTime.MinValue... from this you actually can't subtract anything... otherwise you get the exception you got... see MSDN

Look you date or time data .There not enough digits for date or time Example date must be 8 digit 20140604 and time 6 digit like this 180203.For this reason you are getiing error. i get this error too and find time 18000 and change this to 180000 problem solved.

In your case TimeFrom holds the datetime from which -1 can not be added. You can either invoke

DateTime TimeFrom = TimeTo .AddHours(-1);


DateTime TimeFrom = new DateTime().now.AddHours(-1);

Both of them yield the same result.

In my error, I used the time as 24:00 instead of 00:00

Need Your Help

The correct way to delete and recreate a Windows Azure Storage Table = Error 409 Conflict - Code : TableBeingDeleted

c# azure azure-storage azure-table-storage azure-web-roles

Im really new to Windows Azure development and have a requirement to store some data in a windows azure storage table.