Is there a way to set negative values when calling the DateTime constructor.
like this:
DateTime date = new DateTime(2011, 2, -1);
would be the same as:
DateTime date = new DateTime(2011, 1, 31);
I know this works in other languages, but the problem is that C# .net throws an exception when i'm doing this. Any ideas on how to do this in C# .net?
C and C++ are unusual amongst languages nowadays in making a distinction between signed and unsigned integers. An int is signed by default, meaning it can represent both positive and negative values.
Floating point numbers can be positive or negative.
A real quantity having a value less than zero ( < 0 ) is said to be negative. Negative numbers are denoted with a minus sign preceding the corresponding positive number, i.e., -2, -100.
On all machines, variables of the float, double, and long double data types can store positive or negative numbers.
Use
DateTime date = new DateTime(2011, 2,1).AddDays(-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