Needed Explanation for the expression

Hi Can anyone explain the expression

DateTime.ParseExact(row.Item(“Dată citire contor”).ToString.Trim.Substring(0,10), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)

It takes a date in the format dd.MM.yyyy and as a string, and outputs it in the format MM/dd/yyyy.

This parses the string, in format dd.MM.yyyy into an actual datetime value:

DateTime.ParseExact(row.Item(“Dată citire contor”).ToString.Trim.Substring(0,10), “dd.MM.yyyy”, System.Globalization.CultureInfo.InvariantCulture)

This outputs it as a string in format MM/dd/yyyy:


1 Like

Hi @Sudharsan_AIT ,

The expression you have mentioned is used for parsing.

Let’s suppose you want to get date as per your desired format but you are getting date in string as dd.MM.yyyy format so this is converting date to MM/dd/yyyy.

You have question in your mind why don’t i use Convert.ToDateTime instead of parse exact So you can do that if format of date is same as of your system date then you don’t need this.

In sort this will help to identify the exact format of date and convert it to desired format.

Hope you get it.

1 Like

Thank you @postwick and @ermanoj3101