Assign: String 'Date 11/06/2022 00:00:00 ' was not recognized as a valid DateTime

datetime.ParseExact(OutputTextSQL,“MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MMMM yyyy”)

i read date from sql and want to use select date dynamically, and im put date from sql to output datatable string, so when im convert to datetime still erorr. please help me
strMonthYear is string. OutputTextSQL is String from value Ouput DataTable


Hi,

For now, can you try to add Trim as the following?

datetime.ParseExact(OutputTextSQL.Trim(),"MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMMM yyyy")

If the above doesn’t work, can you share error message and content of OutputTextSQL in LocalsPanel?

Regards,

Hi Yoichi,
Still get the erorr sir.


Hi,

How about the following expression?

datetime.ParseExact(System.Text.RegularExpressions.Regex.Match(OutputTextSQL,"\b\d{2}/\d{2}/\d{4}\b").Value,"MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMMM yyyy")

Regards,

Got it, Thanks you Yoichi.

1 Like

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