This line of code resolved the issue.
var year = result.PolicyData.CommenceDate.Value.Year.ToString();
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I need help please.
Can someone point me to what I am doing wrong in my code below in C#
string year = DateTime.Parse(DateTime.Now.ToString()).Year.ToString();
this code above works.
Why is the code below not working. I want to extract the year out of the DateTime Model(result.PolicyData.CommenceDate)
string year = DateTime.Parse(result.PolicyData.CommenceDate.Value.Year.ToString()).Year.ToString();
the error message is : String was not recognized as a valid DateTime.
Thank you in anticipation of your quick response.
Best regards
Lawrence
This line of code resolved the issue.
var year = result.PolicyData.CommenceDate.Value.Year.ToString();