Change a Date Format

How Do I Change a Date Format?

I have a date variable in the format “MM/dd/yyyy” but I want to change it to “dd/MM/yyyy.” It keeps giving me an error because it’s not a string.

I’m super confused—can anyone help me figure this out

Hi,

Can you try as the following?

image

CDate(strVariable).ToString("dd/MM/yyyy")

Regards,

Hi @Ayushi_Kuhar

Try this way,

Str variable = DateTime.ParseExact("Yourinput",{"MM/dd/yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy")

If you have more input format means you can add in the array

Regards,
Gowtham K

Hi @Ayushi_Kuhar

To change the date format, you can use this code:
CDate(YourDateTimeVariable).ToString(“dd/MM/yyyy”)
This will convert your DateTime variable to the desired format.

1 Like

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