How do you handle NULL in a Date field using C # code?

I am currently setting the date field to Datetime.Now, which is executed through an SQL query in the database.

I do

SELECT NVL(mydatefield, sysdate) FROM myView;

This is not the most elegant approach I can think of. Best practice would be to check for NULL. I found that the DateTime class does not support the syntax that I use for int values.

What approaches did you use? What are your preferences? How can you make a nullTime handle of zero magnitude? I do not want DateTime.ParseExactmy interface code to throw an exception.

+3
source share
1 answer

DateTime? DateTime. default(DateTime) DateTime. DateTime.Min DateTime.Max .

DateTime.ParseExact DateTime.TryParse.

string input = "2010-10-04";
DateTime result;
bool success = DateTime.TryParse(input, out result);
+9

Source: https://habr.com/ru/post/1767946/


All Articles