none
Datetime variables - default values RRS feed

  • Question

  • Hello All,

    I have a object MyObject with a property MyDateOfBirth,

    When I fill the object from DB, I am doing the following..

    if(!dr.IsDBNull(dr.GetOrdinal(1)) MyObject.MyDateOfBirth=dr["DOB"]

     

    Where dr is the data reader, as you see there I am checking for null's, my problem is, if the date is null by default MyDateOfBirth property gets a default date like "01/10/0001" and in the presentation layer when I set the text property of DOB textbox, I get incorrect values.

     

    I dont have this problems in strings because when I declare a string variable, we can set it to null/empty (like string MyString=String.Empty), please let me know how I can accomplish this with DateTime. Thanks. 

    Thursday, June 21, 2007 1:22 PM

All replies

  • I believe DateTime type in .NET Framework always resets date to 01/01/0001 in a case of the NUULs and you cannot change it. What you could do is to declare date property as string, but you would need to remember to handle it as a date in your code. Otherwise you would need to analyze that date for 01/01/0001 value

    Friday, June 22, 2007 3:27 AM
    Moderator