DateModified is when a post is modified, so it doesn't have to contain a value, but can contain a value. Using ADO. NET to get the data from the database assign DateTime. MinValue is there is no value :. You can accomplish my second point by marking the DateModified field as nullable. Now you can set it to null if there is no value for it:. NET to get the data from the database, it will look a bit different to the way it was done above assigning null instead of DateTime.
I hope this helps to clear up any confusion. Given that my response is about 8 years later you are probably an expert C programmer by now :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. DateTime "null" value Ask Question.
Asked 13 years, 2 months ago. Active 1 year, 10 months ago. Viewed k times. Improve this question. Mats Mats Add a comment. Active Oldest Votes. You can also use a nullable DateTime, like this: DateTime?
MinValue : default DateTime or, in more recent versions of C , default. Improve this answer. Dan 6, 4 4 gold badges 36 36 silver badges 87 87 bronze badges. Joel Coehoorn Joel Coehoorn k gold badges silver badges bronze badges.
It would greatly help if you provide an example of how to use it. It's also good to note that when you DO initialize them and with null, they are assigned DateTime. MinValue as well — Jeff LaFay. Value; to read from it, and if MyNullableDate. HasValue to check if it is null — satibel. If you're using. NET 2. Mark Ingram Mark Ingram You can use nullable types even in earlier versions of. NET, no need for 3. It came in. NET in 3. Nullable types are available in.
Net 2. C has had the shorthand? Only VB. Net didn't have the shorthand? MinValue; — Joel Coehoorn. I would use dt. GetValueOrDefault -- it's the most efficient option. Iman Iman This helped me discover passing just null doesn't work. It needs to be DateTime? The value could be either DateTime or DateTime? If it's DateTime? Otherwise, it'll set it to the proper value. By the way, if that's all you're going to do in the getter and the setter, you can use an Automatic Property if you're in VS or above: public DateTime?
The DateTime? What's the actual problem here? Peppers 0. I just felt that he was confused, and some explanation of C would answer his question better than the above.
Friday, July 17, PM. Proposed as answer by newdave Sunday, May 20, AM. You can also use:. Which is what I would use, the only issue would be if the user typed in in a textbox, you could get a matching value. Sunday, May 20, AM. ParseExact methods for converting a string-based date to a System. DateTime object. More about The DateTimePicker control has two parts, a label that displays the selected date and a popup calendar that allows users to select a new date. The most important property of the DateTimePicker is the Value property, which holds the selected date and time.
DateTimePicker How to find date difference? A calculation using a DateTime structure, such as Add or Subtract, does not modify the value of the structure. Instead, the calculation returns a new DateTime structure whose value is the result of the calculation. The DateTime. Substract method may be used in order to find the date-time difference between two instances of the DateTime method.
0コメント