I want to convert a nullable DateTime (DateTime?) to a DateTime, but I am getting an error:

Cannot implicitly convert type ‘System.DateTime?’ to
‘System.DateTime’. An explicit conversion exists (are you missing a
cast?)

I have attempted the following:

DateTime UpdatedTime = (DateTime)_objHotelPackageOrder.UpdatedDate == null 
    ? DateTime.Now : _objHotelPackageOrder.UpdatedDate;

11 Answers
11

Leave a Reply

Your email address will not be published. Required fields are marked *