Date Format change from dd/mm/yyyy to dd.mm.yyyy

How to change date format from dd/mm/yyyy to dd.mm.yyyy while reading from excel.
Like 26/02/2019 I need 26.02.2019 fetching from excel

If your date is stored in a String you can use the Replace function to replace all “/” characters with “.” characters.

If it’s stored in a DateTime you can use ToString(“dd.MM.yyyy”).

3 Likes

[name of your variable].Replace("/",".")

Datetime.parseexact(“26/02/2019”,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantculture).to string(“dd.MM.yyyy”)

2 Likes

If your variable is a string.

Convert.ToDateTime(yourVariableName).ToString(“dd/MM/yyyy”).tostring

2 Likes

So I need to give a excel header name in place of date written.

Hi,

You can use row.item(Column name or index)

I want to fetch from excel header, InvoiceDate is my system header where I have to fetch all the date from excel and put into application after conversion.

No Bro, My date is stored in excel sheet like InvoiceDate and I have to fetch from this column and convert and put into application. Can you tell me how to fetch from excel into conversion format.

I understand but I have to convert it bro before doing this.

Hi,

How to fetch from excel into conversion format?

You cannot get the conversion date from excel because when you get the values from excel its of string type, so you have to convert them to datetime.

As you told you are taking date from excel file and the date you want to put in application,where you are using type into use the below expression

Datetime.parseexact(“26/02/2019”,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantculture).to string(“dd.MM.yyyy”)

So you don’t have to convert separately directly where you are putting into the application, there only it will get converted.

1 Like

Not necessarily true. If date is stored as a date in Excel, it will be read as a DateTime object.
But the column itself is of Type Object, that’s why you can’t directly call DateTime methods on it. You need to cast or convert (which will cast if it was a date), you don’t necessarily have to parse.
Same is true with numbers, they are not read as strings but doubles.

Now, you still can tostring and parse them, but you’re risking mismatch of formats (especially if your formats are not US), but the important bit is that unless you select PreserveFormat dates and numbers (that are recognized by Excel as such) are not read as strings.

@loginerror / @ovi - do we have or could we get a FAQ for this? There’s a lot of topics where this is brought up.

1 Like

We will get to the bottom of it.

There is also a difference in reading the Excel files between reading via Excel Application Scope and the Workbook activities that should be properly documented.

1 Like

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