Can't get the correct datetime format

Hi All,

i have a little task that gets a datatable dt_A of an excel file.
This table will be filtered getting a row only.

After i get the value of the item from this dt_A , located in a string column called “Fecha” which is in this format “dd/MM/yyyy” (its not posible to provide the column in date format due project requirements so i must do it like this)
dt_WithActivityDate.Rows(0).Item(3).ToString

After i ihave to filter a second datatable dt_B (from another workbook) wich have also a column called “Fecha” and i have to use the date extracted previously to filter this dt_B

but UiPath returns the date in an invalid format for me “MM/dd/yyyy” , making the second filter datatable activity fail or getting wrong results

please could you help me to convert the date ?

Thanks & BR!!

Hi

Would recommend to have a view on this thread on similar discussion

@cacafundi

1 Like

Hi Palaniyappan,

thanks for your quick reply!!

yes i have seen this post but i that i need is more simple than this, perhaps if i could filter the datable in another way… i tried also doing this (and i would like to do in this way):

dt_B.Select('[Fecha]=‘“+dt_A.Rows(0).Item(3).ToString+”’”).CopyToDataTable

but the result are not right, because the select returns incorrect values.

thanks & BR

Have you tested to convert to the same format?

newDate = DateTime.ParseExact(dt_WithActivityDate.Rows(0).Item(3).ToString, "dd/MM/yyyy", Nothing).ToString("MM/dd/yyyy")
filteredDT = dt_B.Select("[Fecha]='"+newDate+"'").CopyToDataTable
1 Like

Hi ptrobot,

thanks for your help,
yes i have tried but it returns me invalid datatime in assign activity :frowning:

the dt_WithActivityDate has this data:
[COMBO,Document,Fecha
0200082_F2,CARTOGRAPHY,08/16/2023 00:00:00
]

and the assign is like you said

thanks & br

The date in dt_WithActivityDate is in the format “MM/dd/yyyy”. So switch the place beteween the two date format:

Like this:

newDate = DateTime.ParseExact(dt_WithActivityDate.Rows(0).Item(3).ToString, "MM/dd/yyyy", Nothing).ToString("dd/MM/yyyy")
filteredDT = dt_B.Select("[Fecha]='"+newDate+"'").CopyToDataTable

This is assuming that the dates in dt_B is in the format “dd/MM/yyyy”. Otherwise provide a sample of the dt_B content.

1 Like

Sorry for my mistake :sweat_smile:
the data table posted ,dt_WithActivityDate, is the dt that i called dt_A for this example , which contains the date that i need to format and use to filter in the dt_B

dt_WithActivityDate is dt_A → which contains only a row (posted above)

dt_B contains the following values:

COMBO,Doc_type,Fecha
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
0200082_F2,CARTOGRAPHY,08/15/2023 00:00:00
]

Thanks for be patient!!

BR!.

Hi @cacafundi

  1. First, use the dt_WithActivityDate.Rows(0).Item(3).ToString expression to get the date as a string in “MM/dd/yyyy” format.

  2. Then, use the DateTime.ParseExact function to convert it to the desired format like this:

DateTime.ParseExact(yourDateString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

Replace yourDateString with the variable or expression that contains your date in “MM/dd/yyyy” format.

For example, you can assign the converted date to a new variable like this:

Dim convertedDate As String = DateTime.ParseExact(yourDateString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")

Now, convertedDate will hold the date in the “dd/MM/yyyy” format, which you can use to filter the second datatable dt_B.

Hope it helps!!

1 Like

Both dt_A and dt_B has the date in the same format MM/dd/yyyy (month/date/year). So you should be able to compare the dates without converting them. Strange.

1 Like

Hi all,

thanks for your help, i attach the flow and the documents to help you explaining my flow :slight_smile:

BR.

Please , forget the post and forgive my mistakes.
I dont realize that i was using the same datatable to store the results in some activities.

this is the cause of wrong results:

Sorry again cheers!

Thanks & BR

1 Like

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