public DateTime? SubscriptionStartDate { get; set; }
I want the datetime in string format after it has mapped a value:
SubscriptionStartDate = sheet.AUDIT_SHEET_SUBSCRIPTION_START_DATE
But i cant convert it to a string. I get the exception in my topic. I think i need to convert it to a non-nullable datetime object using the ?? operator, but im not sure how, since i never used it.
you need to check it has a value, then you can get the tostring from it. eg:-
if(SubscriptionStartDate.HasValue)
{
String myValue = SubscriptionStartDate.Value.ToString();
}
It is easy to use + operator
public DateTime? SubscriptionStartDate { get; set; }
string result = "" + SubscriptionStartDate
Not sure this is a nullable issue per say.
Try (making sure to check for null first):
SubscriptionStartDate.parse( sheet.AUDIT_SHEET_SUBSCRIPTION_START_DATE )
( assuming you are retrieving a string and trying to assign a DateTime.... )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.