c# - DateTime.Parse takes min date value if null -
i have asp.net application in have textbox enter datetime value , saved in database.
now when trying retrieve date, shows 1/1/0001 12:00:00 if date null.
this.firstreceiveddate = datetime.parse(dr["firstreceiveddate"].tostring());
apologies, requirement changed. want show blank ('') if firstreceiveddate null.
how can that?
you try below:
datetime date = datetime.parse(dr["firstreceiveddate"].tostring()); this.firstreceiveddate = date != datetime.minvalue ? date : datetime.now;
since parsing correctly, ought work.
alternatively, if want value when date null, can try this:
datetime date; if(datetime.tryparse(dr["firstreceiveddate"], out date)) this.firstreceiveddate = date != datetime.minvalue ? date : datetime.now; else this.firstreceiveddate = datetime.now; // or whatever want if "firstreceiveddate" not valid date.
Comments
Post a Comment