Convert to date format -"YYYY-MM-DD"

Hi team ,

I want to convert the below dates

variable A = 9 March 2022
variable B = 09 Mar 22
variable C = 09/03/2022
variable D = 9 Mar 222

to 2022-03-09.

Can you please help me to the same.

Regards,
G

have a look there and see on how we can handle multiple formats by
grafik

arrFormats = {“d MMMM yyyy”, “dd MM yy”…}
DateTime.ParseExact(row(0).ToString.trim, arrFormats, cultureinfo, DateTimeStyles.None)

ensure following:
import_systemglobalization

Hi @gokul1904 ,

if you can identified input format then only you can able to convert excepted format

Ex:

(input) stTest= 30/12/2022

DateTime.ParseExact(stTest,“dd/MM/yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“MM-dd-yyyy”)

Output = 12-30-2022

Thanks,
Rajkumar

1 Like

Hi @gokul1904 find this screebshot. You can modify your code according to your requirement.

use MMMM for full name of month

Hi @gokul1904
For variable 1

DateTime.ParseExact(stTest,“dd Month yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)

For variable 2

DateTime.ParseExact(stTest,“dd Mon yy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)

For variable 3

DateTime.ParseExact(stTest,“dd MM yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)

For variable 4

DateTime.ParseExact(stTest,“dd Mon yyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)

Hello @gokul1904
All above formats can accept the below code, try this

DateTime.ParseExact(YourString.Trim,{"d MMMM yyyy","dd MMM yy","dd/MM/yyyy","d MMM yy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")
1 Like

Hello @gokul1904

You can do the same with the Modify Date Activity also.

Thanks

CDate(VariableA).ToString(“yyyy-MM-dd”)

dt_yourDate.ToString(“yyyy-MM-dd”)

please note the MM should be capital letters

You need to first convert the string to date format base on format given then you can convert the date to specific date formate using system.Globalization.CultureInfo.InvariantCulture

You’ve dug up a post that is almost 2 years old…