how do i get the date of the string in c closed?

To use date formatting, you need to start with a DateTime object, not a string.

So in your scenario you’ll have to parse your string as a DateTime, then format it out again to a different string format. There’s no way to directly format string -> string, all the logic about formatting is in the DateTime class.

Here’s an example:

string changed = "Wed, 02/05/2020 - 12:31";
var checkresponse = DateTime.ParseExact(changed, "ddd, MM/dd/yyyy - HH:mm", CultureInfo.InvariantCulture);
string issueDate = string.Format("{0:MM/dd/yyyy}", checkresponse);


(Alternatively, since what you mainly want to do here is strip the first and last parts of the string and keep the date part, you could use a regular expression do to this from the string, but overall it’s probably more reliably to use date parsing and formatting.)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top