Convert a string to datetime with specific format

Input String =“February 29 2021”
Output string = 02.29.2021
Here I shared input and output format can anyone pls help me to how to convert input as like output using datetime

Note: When i using convert to date, its throwing error input string is not correct format

Thanks in advance,

“February 29 2021” is not valid date since year 2021 is not a leap year. Change it to valid date and then convert it like this:

strInput = "February 28 2021"
strOutput = DateTime.ParseExact(strInput, "MMMM d yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM.dd.yyyy")

Thanks, I lost mind to think that

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.