I'm adding an object to a list within an ASP.NET MVC 3 application using the following code but one of the properties of the object is giving me difficulties.
ls.Add(new UserRoleModel { UserRoleId = 1, UserName = "Paul", InsertDate = new DateTime(05, 24, 2012),InsertProgram="sqlplus",InsertUser="sp22",Role="Implementation Co-corindator"});
This builds but when I go to the relevant page i get an Exception with the following type:
Exception Details: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
I've tried removing the 0 in the month but I get the same exception.
The DateTime
constructor you are calling accepts parameters in the order year, month, day.
You are providing them in the order month, day, year -- which ends up trying to assign meaningless values. The documentation is pretty clear on what the allowed values are and what happens if you pass 2012 for the "day" value.
I just ran into this and my issue was I was creating a date in February. I tried to do the following...
new Date(2013, 2, 30)
Since there is not a February 30th, the date failed to create. When I changed to
new Date(2013, 2, 28)
it worked fine.
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