How can i convert DD/MM(Months in Words) to MM/DD/YYYY format

i have this
01
Mo
Aug

kind horrible format date coulmn and my firend convetted it to DD/MM(Months in word)

output is like ths
01Aug,02Aug, and so on

The year is 2022

here is what he have done

v_arr_ColumnName = v_dt_DB.Columns.Cast(Of DataColumn).where(function(col) System.Text.RegularExpressions.Regex.IsMatch(col.ToString,"\d+")).Select(function(x ) x.ToString.Replace(vbLf,"").Split(" "c)(0)+x.ToString.Replace(vbLf,"").Split(" "c)(6)).ToArray

for getting that kind of output

now i want to convert it to MM/DD/YYYY

output what i want is like this 8/1/2022 , i dont want 0 before a single number

eg 01 i want 1 (both for month and date)

1 Like

Hi @indiedev91

Can you share the sample input here with the format?

Hi @indiedev91

You can try with this expression

DateTime.ParseExact(StringInput.ToString,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

You can simply add the any number of date formats dd/MM/yyyy

Regards
Gokul

Please look at the DB(WDF) sheet in this Gsheets

Can you share the Output also for that? @indiedev91

output before implemening your solution

after implementing you solution there is an error

"Source: Assign

Message: String '01Aug' was not recognized as a valid DateTime.

Exception Type: System.FormatException"

HI @indiedev91

Try with this expression

DateTime.ParseExact("01Aug","ddMMM",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

image

Regards
Gokul

Thanks a lot it is working now ,just one last thing can you tell me how can remove the zero befor a single number date or month?

Can you share the sample input and output? @indiedev91

HI @indiedev91

If your input like this

01
11
12
05

You can try with Regex expression

System.Text.RegularExpressions.Regex.Replace(YourString,"^0","").Tostring

Regards
Gokul

Hi @indiedev91

Kindly close this topic by mark as solved it will help for other too.

Regards
Gokul

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type ‘dd-mmm-yyyy’ in the Type text box, then click okay. It will format the dates you specify.

Regards,
Will

hey thanks for the answer, sorry but can you help me one last time, actuallly the coulmn name was stored in an array of string but as in this expression

v_arr_ColumnName = DateTime.ParseExact(v_arr_ColumnName.ToString,"ddMMM",System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy")

i cant able to pass array in place of string and i also want to store the output to the same array of string “v_arr_ColumnName”

after this first one

now its time for removing the zero

v_arr_ColumnName = System.Text.RegularExpressions.Regex.Replace(v_arr_ColumnName ,"^0","").ToString

Hi @indiedev91

Check out this XAML file

ArrayStringTest.xaml (9.4 KB)

image

Regards
Gokul

@indiedev91 Please mark it as solution so that it can help other people

Thanks

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