Date Format "dd/MM/yyyy" Goes Wrong While Writing in Excel

Hello All,

I get a date from Date.Today.ToString(“dd/MM/yyyy”) and my date format in Excel is English(United Kingdom) which is same format (dd/MM/yyyy) . However when I use ‘Write Cell’ function into Excel sheet the format turns to “MM/dd/yyyy”.

How can I solve this problem? (Yes I tried calculate again and text to column function but they don’t fix it neither.)

Also what I realized, it only does this error while there is 01 in the date. So today is 02/01/2020 according to my format bit it keeps writing 01/02/2020 to excel. This error keeps happening to me if there is ‘01’ in the date doesn’t matter in month or day part.

Thanks in advance

@mernst

It’s excel format issue not with your code.

First define required format in that Excel file and then write into Excel file.

I specifically indicated it in my question–> my date format in Excel is English(United Kingdom) which is same format (dd/MM/yyyy)

So yes I did that definition already and it doesn’t fix it.

I think it is worth trying to use " ’ " before and concatenate with your date in the write cell activity, just like: “'” + Date.Today.ToString(“dd/MM/yyyy”)

1 Like

In visual aspect, it is definitely a smart move but I am uploading this file to SAP later on and SAP doesn’t accept " ’ " .

So it is unfortunately not the solution. Thanks for your suggestion though.

Hi @mernst

try this

Now.ToString(“dd/MM/yyyy”)

Thanks
ashwin S

Hi @mernst,
Just for a reference, can you explain how you defined the date format in the excel?

As in the screen shot.

Are you selecting the entire column while defining the date format?
And also try Custom formatting category and use Type as dd/MM/yyyy

Hi! I have the same issue, what I did was grab the value of the table and convert it to date time, then I write it where I need it with the format I need.

Note: the variable “dateNacimiento” is a DateTime variable.

image

Yes I did for entire column, and nope custom formatting also doesn’t solve the problem.

I also want to repeat again I face with this issue when there is ‘01’ in the date. For the other dates which doesn’t have ‘01’ in it such as "13/08/2019 " this error doesn’t happen. I think it is a bug.

Thank you @dark_vicious but I still look for a better and more practical solution as your solution will make my robot very slow. I have a massive excel sheet and more than one. Writing them one by one is not a case.

Hi @mernst, how did you crack this one ?thx

Hi @mernst, not sure if it is too late. I had the same issue. I resolve it using .ToOADate to convert the date string into double. The double will be converted according to your Excel’s cell format

I have the same issue @mernst had, but I haven’t yet solved it.
I tried @RainbowDonkeys 's solution but it doesn’t work well…
Does anyone can solve it? Thanks in advance.

Will the file change or will it be a fixed file throughout the processes? Is it possible for you to pre-format the cell in excel to your desired date time format?

Hi,
I have the same issue as the author of this thread. Have rows over 35k, and Studio changes the date format on write back to Excel.
Anyone has a solution for this please !

Hi all, sorry for reviving such an old thread. I wanted to share my experience trying to find a solution for this, as I spent way more time on it than I initially intended to. I hope that one of the methods I list below can save someone else a few headaches.

Just like many other users, my date format in Excel is set to dd/MM/yyyy.
This default formatting is based on the regional settings of your operating system. A quick way to check those is using the command WIN + R and then opening intl.cpl.

Inside my UiPath Studio the default DateTime formatting is set by default to MM/dd/yyyy.
Using System.DateTime.Now would return a DateTime such as “12/09/2022 16:30:21”.
Since this formatting is not what we use here, the commonly used method it to get our local formatting would be System.DateTime.Now.ToString("dd/MM/yyyy") or Date.Today.ToString(“dd/MM/yyyy”).

This does the trick inside the UiPath environment, as the returned String would be “09/12/2022”, but as soon as I used a ‘Write Cell’ activity to return this value to my Excel it would revert the format to MM/dd/yyyy and write “12/09/2022”.

Frustrating, and none of the methods I read in other threads worked for me. I used DateTimeParseExact, substrings, saving it in variables of various types, changed the CultureInfo of the entire project, etc. All to no avail. The result is correct in all my logged messages, but as soon as I write that very same value to Excel, it reverts to the MM/dd/yyyy format.

Using "'" + System.DateTime.Now.ToString("dd/MM/yyyy"), so just adding a ’ before the value to be written into my Excel file was half a solution, but I need to feed this data in a different program that does not accept a ’ before a date value. I wanted to be able to remove this apostrophe in the same run, but doing so would result in the same change in formatting, even when using ‘Modify Text’ on the active Excel value and returning the modified StringValue.

Here’s two methods that did end up working for me:
Instead of trying to convert the DateTime value inside the UiPath environment, I tried to force the ‘Write Cell’ activity to return the value in a specific format.

One method that ended up working was formatting the range of cells in which the DateTime values would be written. Not as text, but as a custom DateTime formatting that forces the locale that I use.

I stumbled upon this bottom option when browsing through the custom formatting options:

image

This gave me the idea to use a ‘Format Cells’ activity with the following Custom format:
[$-nl-BE]dd/mm/jjjj

image

Depending on your locale nl-NL, de-DE, en-GB, etc. you should be able to force the DateTime value to be written using the dd/MM/yyyy formatting using the locale of your Excel settings rather than the default setting of the UiPath environment. Note that jjjj is Dutch formatting, it will probably still be yyyy if you use en-GB.

Important: if you do this, there’s no need to format the System DateTime in the UiPath environment for this specific ‘Write Cell’ activity. Just grab the Date part and use that, do not change it to dd/MM/yyyy in Studio. I used DateOnly.FromDateTime(System.DateTime.Now) and stored it in a DateOnly type variable, but I’m assuming Date.Today might work too.
It will show the wrong formatting inside your UiPath environment since you’ll be using the default DateTime format of the environment, but it will get converted in your Excel file.

If I use this variable in my ‘Write Cell’ activity, the returned value in my Excel file uses the dd/MM/yyyy formatting that I need.

Alternative:
If you are unable to pre-emptively format the cell: I found out that even without forcing your locale in the cell formatting, using the DateOnly.FromDateTime(System.DateTime.Now) in my ‘Write Cell’ activity would return the dd/MM/yyyy formatting that I need. I keep using the pre-emptive format so that I know for sure my desired locale will be pushed, but it should also work without it as long as your regional settings are set to a location that uses this type of date formatting. The only notable difference between these two methods is that this alternative would return “9/12/2022” rather than “09/12/2022” since that’s the default Date formatting that gets recognized in my Excel file. If you prefer the double digits, use the Custom formatting method.

It seems that the crux of the issue is that most of us try to convert the DateTime formatting inside the UiPath environment, but that when using the ‘Write cell’ activity some other conversion is done that reverts the desired result back to the original formatting. When refraining from modifying the DateTime value in the UiPath environment, but rather trying to do so in the Excel environment, things worked out for me.

Hopefully this helps someone else too!