How to assign ( set ) Null value to DateTime Variable in C# .Net

on Mar 08, 2013 02:53 AM

How to assign Null value to datetime variable using nullable

I am getting a value from the textbox (I select a date)

but, may be sometimes user not select any value to the datetime textbox

in that cases i compare with null

i do like , but it gives me error

 DateTime? ScheduleDate = txtScheduleDate.Text;


                    if (ScheduleDate.HasValue)
                        ScheduleDate = Convert.ToDateTime(txtScheduleDate.Text);


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Mar 14, 2013 03:03 AM

Do this way

 DateTime? ScheduleDate;
 ScheduleDate  = Convert.ToDateTime(txtScheduleDate.Text);
   ScheduleDate  = null;