I have a variable which is expiryDate from object product. The property of the expiry date is as below:
public DateTime? ExpiryDate{ get; set; }
The date is returned in the following format:
2020-01-15 11:16:40.6071922
Because my DateTime for ExpiryDate is nullable, when I try something like this:
var expiry = DateTime.ParseExact(products.ExpiryDate, "yyyy/MM/dd HH:mm:ss", null);
I get the below error:
CS8604 - Possible null reference argument for parameter 's' in DateTime DateTime.ParseExact...
I can suppress the error, but this is not what I want to do. Is there anyway to remove the milliseconds without having to convert to string.