Problems in DateTime

Hello @Ignacio_Insua_Feito.
Is it possible to swap the values of the Month and Day?
The bot read the date uncorrectly from the Excel.
Thank you so much :slight_smile:

Hi @CamiCat i don’t understand exactly which is the problem now.

However, i will suggest a general solution step by step.

  1. Place logs in each place:

a) Just after read (it does not matter the origin)
b) Just before conversion
c) Just before write

  1. Understand the problem:

If you are reading from excel the problem normally its that UIPath converts it to a “Generic Value” type where you actually lose the control of the item (What UIPath its doing internally, no ones know). Normally if you detect the log writes wrong “just after read” the best solution its a Format Value activty where you can set how it will be converted to string.

If you read it from another source with different format and you need to write it to an excel and you need it to get date format then you should parse to date with a datetime.parse(yourDateAsString) [Here is when you may need to set culture info].

In case you write that date and still fails because it change day with month dont worry, there is another solution which is convert it to excel real storage format its called OADate format. (OADate is a double value that reffers to a date from 1/1/1900). If you set the format in your excel before or after editing the work will be done

Sorry for the complex answer but its a big problem in every programming language… (f**k dates)

1 Like

Hi @Ignacio_Insua_Feito.
My problem is this one:
I’m reading the date from an Excel file.
The date is save in Date Format in the Excel File.
preprocessing.xaml (44.8 KB)
I attach the xaml in which I manipulatethe date. I have to save the date in another Excel File but it saves the date in the incorrect format: month/day/year.
CAn you please help me in resolving this issue?
Maybe with a OADate format? CAn you please tell me how it works?
Thank you so much,
Camilla :slight_smile:

Sorry, i can’t read your XAML cause i dont own any UIPath License of my own (Doing this in my spare time).

In case you read the date from that Excel. just try with format value activity.

  1. Create a “Generic Value” variable
  2. Assign it a value (read it from excel)
  3. Create a “DateTime” variable
  4. Parse to datetime (this could be conflictive, try with Datetime.parse(yourDateAsGenericValue.ToString)
  5. Work with your date
  6. Assign it backwards to your “Generic Value” variable.
  7. Format value to define how you have wrote the value (using format value activity)
  8. Write to excel.

And just remember typed variables do a bit of their own work internally so if you just use variable.tostring you may not know what is actually stored in there. For Example: Datetime variable can show you dd/MM/yyyy or MM/dd/yyyy formats if you use only tostring.

There are two ways to know what is inside them: Preformat the input to a known type (in case of datetime you can use any property like .day or .month or .year to clear any doubts on the contents) or in case its a Generic Value you can use a format value activity.

1 Like

HI @Ignacio_Insua_Feito,
It is really a nice Post. Superb . But the problem is in the reading values from the excel which is having the date format. Here I have attached the sample which comes form @CamiCat. it is always swap the values like MM/dd/yyyy. It doesn’t recognize the actual format (dd/MM/yyyy) which we specified in the excel sheet. Please take look.

File: (8.6 KB)





1 Like

Hi @Ignacio_Insua_Feito,
This works fine.

@CamiCat. you can not use the format like (“dd/mm/yyyy”)

Here I have attached the sample which i have tested
file : (8.9 KB)



Thank you so much @balupad14.
It seems working.
I finish testing and I let you know.
Thank you
Camilla :tada::tada: