String" Was not recognised as valid DateTime again

Greetings,

I am trying to change the date format of a string variable

strdateA= “24/03/2024”

desired Output is Mar-24 i.e in the format of (“MMM-yy”)

Here when I am passing the syntax in the second variable which is also a string type i.e. strNewDate = Datetime.Parse(strdateA).Tostring(“MMM-yy”)

I am getting the above error.

I tried changing the variable type to DateTime but no use even I tried to change the sytnax by convert.datetime(strdateA).tostring(“MMM-yy”)

whats would be the issue here?

Hi @Anirudh_Tugawe

Please retype the double quotes ". This should solve

strNewDate = Datetime.ParseExact(strdateA,"dd/MM/yyyy",System.GLobalization.CUltureInfo.InvariantCulture).Tostring("MMM-yy")

Regards

Hi @Anirudh_Tugawe

Try this

DateTime.ParseExact(strdateA, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMM-yy")

Thanks for your fast reply, I changed it according to your comment but no use. it throws the error string that was not recognized as a datetime

Hi @Anirudh_Tugawe

Try this:

strNewDate = Datetime.ParseExact(strdateA,"dd/MM/yyyy",System.GLobalization.CUltureInfo.InvariantCulture).Tostring("MMM-yy")

Regards

Check the below image for better understanding @Anirudh_Tugawe

Regards

@Anirudh_Tugawe

DateTime.ParseExact(strdateA, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MMM-yy")

1 Like

@lrtetala @Parvathy

DateTime.ParseExact(strDateA, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MMM-yy”)

I was using “-” instead of “/” in the date format, maybe because of that it was showing me the error.

Thank you Guys you both are correct

Yes @Anirudh_Tugawe

that is the issue you are using “-” instead of “/” in the date format

Please close the topic by mark it as solved.

Regards,

Last question can we switch Column A to Column B and vice versa in an excel?

Yes @Anirudh_Tugawe

If the format is same in 2 columns you can

yes, it is required to switch the columns just

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