Answer the question
In order to leave comments, you need to log in
Which data type to choose in datetime or string class?
Created a class. Parsing XML file. Using EF, I insert objects into the database.
What is the best data type to choose for a property that may or may not store a date?
datetime or string? In XML, the information contains information about the time, and sometimes it does not. If not, then null should be inserted, but Datetime does not support the nullable type.
What's the best way to do it?
Answer the question
In order to leave comments, you need to log in
Use DateTime?
, with a question mark. It's like a regular DateTime, only it can be NULL. It is specially designed for such cases.
It's not clear what's the catch - where do you define the data type? If in the database, then go to the database documentation:
CAST('2007-05-08 12:35:29. 1234567 +12:15' AS date...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question