I am reading field values which may have an unformatted date in them or whitespace, i need to convert the string in the filled fields to datetime and write it back. I'm trying the following but get the error "Nullable object must have a value":
DateTime? localVersion = null;
DateTime? serverVersion = null;
if(!string.IsNullOrWhiteSpace(item.cellValueLocal))
{
localVersion = DateTime.ParseExact(item.cellValueLocal, "ddMMyyyy", System.Globalization.CultureInfo.InvariantCulture);
}
if (!string.IsNullOrWhiteSpace(item.cellValueServer))
{
serverVersion = DateTime.ParseExact(item.cellValueServer, "ddMMyyyy", System.Globalization.CultureInfo.InvariantCulture);
}
localVersion.Value.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture);
serverVersion.Value.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture);
Can anyone offer any guidance on what the issue might be here please?
DateTime? localVersion = new DateTime(2015, 1, 18);'item.cellValueLocalis null or whitespace?localVersionandserverVersionwon't have a value you can calltoString()on.ToString(), but not doing anything with the return value.