C check datetime null
Improve this question. Morteza Azizi 5 5 silver badges 22 22 bronze badges. DateTime can't be null or empty. What's the actual problem? TryParse — Juan. Are you using a specific control like DateTimePicker that has documentation? My task is to take in a date of birth from a user interface, and the only validation that is asked of me is to throw an argument exception if the date of birth field is blank on the GUI when a button is clicked — x4iiiis.
Add a comment. Active Oldest Votes. Improve this answer. Jakub Lortz Jakub Lortz HasValue only exists if DateTime is nullable if date. HasValue Console. WriteLine "date has a value" ; else Console. WriteLine "date is null" ; If your DateTime is not nullable, make it nullable unless you are absolutely certain in will never be null. So which option should I use to use "best practice"? Improve this question. Stewart 3, 3 3 gold badges 25 25 silver badges 36 36 bronze badges. In your first sentence after the code blocks, do you mean "second version", or did you mean "third version"?
Updated it ; I meant the third version, since the property clearly explains what I intend to check: if the variable has a value — dasheddot. And what happens when whatever it is actually does happen at that min date? If the database has date fields that are not null does that mean it always has valid dates in in which case we don't need to worry or do they use some kind of default. If the latter can you test what that default is somehow or is it inserted by the code?
Nullable is certainly what you should be using here Chris The bad thing is that the database is designed in the way that it has not null columns but the business logic allows invalid or default dates. So in this cases we decided to use. Net's default DateTime value to store in the db to project invalid dates. But as I described Nullable would be my favorite too, but in these cases sadly not possible.
Show 1 more comment. Active Oldest Votes. MinValue; Okay, so I'd make the name slightly less wordy, but you get what I mean. Improve this answer.
Jon Skeet Jon Skeet 1. For MY context not able to adapt database to support nullable datetime columns I unfortunately need to go without Nullable. So your suggestion is most acceptable, cause by making this explicit the business rule behind the check can be realized easier. I will go this way. Accepted it, thanks! Add a comment. LukeH LukeH k 53 53 gold badges silver badges bronze badges. Based on that assumption, this is how I would write this code.
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. How to check if DateTime is null Ask Question. Asked 9 years, 11 months ago. Active 8 years, 8 months ago. Viewed 43k times. I would like to know how will I be able to do checking for the endDate. Improve this question. Paul Hiemstra Then use a constant to represent the value which DOES correspond to null in the Calendar control you are using.
Add a comment. Active Oldest Votes.
0コメント