I have an asp.net form with C # where I take user information to insert into the database, as usual, using Linq. Well. Where, how do I get the date of birth also from the user, but if the user skips the date field text box from ui, then I get the date as '01 / 01/0001 ', something like this, which, of course, database security will not allow keep it.
So I need to check somewhere in my code that it is null or in this (above) format. If it is null or in the format '01 / 01/0001 ', then what exactly do I need to do? I have no default settings for dates.
So, what is the standard way of processing if the date is zero (but not necessary). Please guide me. So many times I have been trapped by accessing null for different types.
Edited let's see what I did, it seems to work here. but I don't think this is the standard way:
DateTime? otxtDOB = new DateTime(); if (!string.IsNullOrEmpty(DOB)) { if (Convert.ToDateTime(DOB) != DateTime.MinValue) { otxtDateOfPurchese = Convert.ToDateTime(Convert.ToDateTime(DOB).ToString("dd-MMM-yyyy")); } else { otxtDOB = null; } }
Please confirm that this is the right way?
source share