Assign String was not recognized as a valid DateTime

Hi Team

I have to convert the different input date formats into a specific output date format.
input:- ‘23-10-2023’
output- ‘23 Oct 2023’

But I have made some errors.

How can I solve this error:-

Assign: String ‘23-10-2023’ was not recognized as a valid DateTime.
System.FormatException: String ‘23-10-2023’ was not recognized as a valid DateTime.

Thanks
Minal P

1 Like

@minal.patil

datetime.parseExact(vDate,{“dd/MM/yyyy”,“dd-MM-yyyy”,“MM-dd-yyyy”,“yyyy-MM-dd”,“dd-MMM-yyyy”},system.globalization.cultureInfo.invariantculture).tostring(“dd MMMM yyyy”)

1 Like

image

datetime.ParseExact(Input,“dd-mm-yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd MMM yyyy”)

Hi

Say you have a date string which can be of different formats for each time it is being used like
“dd/MM/yyyy”, “MM/dd/yyyy”, “dd/yy”

Then have all these possible formats in a array variable named arr_formats

Like this

arr_formats = {“dd/MM/yyyy”, “MM/dd/yyyy”, “dd/yy”}

Then to convert that string as Datetime

var_datetime = DateTime.ParseExact(Strinput.ToString, arr_formats, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None)

Cheers @minal.patil

it’s working thanks.

1 Like

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