Sorry if this seems as a stupid question, but I cannot find an answer anywhere and I am a bit of a newbie. DateTime shows to be what I surmised as the Min Date. For instance:
DateTime updatedDate = new DateTime();
outItem.AddDate = updatedDate.ToLongDateString();
The output comes out to January 01, 0001. I've tried many variations of this with similar results. What am I doing wrong?
It depends on what you mean by "wrong". new DateTime()
does indeed have the same value as DateTime.MinValue
. If you want the current time, you should use:
DateTime updatedDate = DateTime.Now;
or
DateTime updatedDate = DateTime.UtcNow;
(The first gives you the local time, the second gives you the universal time. DateTime
is somewhat messed up when it comes to the local/universal divide.)
If you're looking to get the current date, use DateTime.Now
. You're creating a new instance of the date class, and the min value is its default value.
DateTime updatedDate = DateTime.Now;
outItem.AddDate = updatedDate.ToLongDateString();
EDIT: Actually, you can shorten your code by just doing this:
outItem.AddDate = DateTime.Now.ToLongDateString();
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