You need to call the Value property of the nullable DateTime. This will return a DateTime.
Assuming that UpdatedDate
is DateTime?
, then this should work:
DateTime UpdatedTime = (DateTime)_objHotelPackageOrder.UpdatedDate == null ? DateTime.Now : _objHotelPackageOrder.UpdatedDate.Value;
To make the code a bit easier to read, you could use the HasValue property instead of the null
check:
DateTime UpdatedTime = _objHotelPackageOrder.UpdatedDate.HasValue
? _objHotelPackageOrder.UpdatedDate.Value
: DateTime.Now;
This can be then made even more concise:
DateTime UpdatedTime = _objHotelPackageOrder.UpdatedDate ?? DateTime.Now;