Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

how to Convert and formatting iso dates in C#

$
0
0

I have this DateTime property in a DTO

 public DateTime Dob { get; set; }

and in my code I m running a for loop to match data and manipulate them as well,

 for (int i = 0; i < PatientInfo.Count; i++)

            {
                PatientInfo[i].Dob =
                DateTime.ParseExact(PatientInfo[i].Dob.ToString("MM/dd/YYYY"), "MM/dd/YYYY", DateTimeFormatInfo.InvariantInfo);

                PatientInfo[i].PartnerData = PartnerInfo.Where(a => a.FileId == PartnerInfo[i].FileId).ToList();

            }

I m trying to convert the iso date in Dob ("1984-04-26T00:00:00") to just a date as MM/dd/YYYY but the code above fails, keeps returning the same value. I tried also parse and TryParseExact but they failed too

what am doing wrong here?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>