Error in using DateTime.Parse method in assign activity

Hi All,

I am trying to convert string format date into a datetime object and it is giving an error.

Before the explanation, I am mentioning the following dependencies:

  1. .NET framework (v4.6.1 as per UiPath Studio latest version).
  2. .NET framework (v4.6.1 as per Visual Studio).
  3. C# as the language for custom operations.

I am able to run this piece of code in Visual Studio and getting the desired output in Visual Studio. But, the same is failing in UiPath even though the .NET framework version is same.

I am using the following code :


{
    var d = Convert.ToDateTime("29.09.1999");
    Console.WriteLine(d.ToLongDateString());
}

Screenshot (313)

As you can see from the screenshots all dependencies are same.
If the framework and code is same, why is it failing in UiPath ?
I cannot figure out why is it happening.
If any clues please let me know.

Thanks.

1 Like

@tushar.tripathi - i see only 0 in the month…i guess you missed 9…

image

cdate or Convert.todatetime will convert the date based on the locale settings of your system…

Since mine is mm/dd/yyyy , my first statement errored here…whereas my 2nd statement worked fine because it is in mm.dd.yyyy format

image

Hope this helps…

Hi There !

Sorry that was a typing error.
I have updated the thread please check it again.
Sorry for the inconveniences.

Another thing, the convert works the both way when run in visual studio . “29.09.2021” or “09.29.2021” both works fine in Visual Studio.

The Format dd.MM.yyyy requires a Handling of e.g using DateTime.ParseExact(…

The local Format ist Not undestood by the Default conversions methods

Hi !

I know about the ParseExact method. But my concern is why the Convert class not able to do so here. I mean the convert class in UiPath and Visual Studio are same right ? Then what’s making the code to crash in UiPath ?

@tushar.tripathi
Is IT ensured and verified that IT IS working on c# in vs with excactly this String 29.09.2021?

If yes please Share the Screenshots with us clear showing IT. Feel free also to Show us the Democase Done on a .net fiddle or similar else

1 Like

Hi there !

The screenshots I have posted are from the same device. The UiPath screenshot attached has clearly mentioned the way I am trying to parse. If you see at the bottom right, the .NET version is 4.6.1 and the time format is also the same. Coming to the other two screenshots of visual studio, there also it is mentioned the version of .NET used for executing the code. The syntax and .NET versions are clearly mentioned if you take a closer look and I am very much sure that in Visual Studio

Convert.ToDateTime("29.09.2021")

is parsed exactly the way it should be.

No not on 29th Sep 2021

share exactly this screenshot parsing 29th Sep 2021 with us again. Thanks