Formatting a string date

Hi guys, I want to format a date in a Txt file From 25-11-2023 12:58:03 to 2023-11-25 12:58:03. Is there a way to do that?

Hi @Woodson_Louis1

Welcome to our community!

Kindly try with the following

DateTime.ParseExact(strInput, "dd-MM-yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd hh:mm:ss")


Hi @fernando_zuluaga

what is written in my text file is more like this to be clearer:

25-11-2023 12:58:03;str2;str3;str4;str5;str6;str7;str8
15-07-2023 01:22:01;str2;str3;str4;str5;str6;str7;str8
12-11-2023 12:00:00;str2;str3;str4;str5;str6;str7;str8
25-04-2023 05:00:03;str2;str3;str4;str5;str6;str7;str8
11-01-2023 12:11:00;str2;str3;str4;str5;str6;str7;str8
01-11-2023 03:49:54;str2;str3;str4;str5;str6;str7;str8

I need to change the date format for every row but the system

don’t recognize the column1 as a DateTime

You should replace strInput variable for your current row


Can you try the following expression?

yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"(\d{2})-(\d{2})-(\d{4}) (\d{2}:\d{2}:\d{2})","$3-$2-$1 $4") (2.4 KB)


1 Like

It works!!! Thanks @Yoichi & @fernando_zuluaga! Really helpful :wink:

1 Like

Hi @Woodson_Louis

Kindly remember to close the topic marking the solution that works in this case


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