I tried to read cell in excel when its a date time format, but when i try to output it to string, i have error “string converter cannot convert from system.datetime”. Can i just read the excel value as string with read cell or i can try different activity?
Hi,
Can you try to use UiPath.Core.GenericValue type as the following?
If we need string type, just use .ToString method, like genVar.ToString()
And we can manage its type using FormatValue activity.
https://docs.uipath.com/activities/docs/format-value
Regards,
have you tried like this way :
-
Use Excel application scope activity
-
Use Read cell activity
You can check that in the GenericValue
and use .Tostring to avoid the issue
Regards
Gokul
Whenever you read data from excel make sure you read it as uipath.code.GenericValue and once it is read you can cast it to whatever datatatype you need as when reading cell excel cel activity will cast the value to its base type …to avaoid the errors its better to read as genericValue
Cheers
thanks for the reply! its work when i change the data type to generic, but uipath read the data and auto convert it to date format, for example in excel it say 12/9/2022 wich 12 September 2022, but uipath read it as 9 December 2022, can i just get the string of 12/9/2022 as the value? sorry for my english hope you can understand
thanks for the reply! but i can’t use assign since the error exist early when i read the cell
thanks for the reply! its work when i use generic value as ouput but the value is auto generate to date format
You can try with this expression
DateTime.ParseExact("9 December 2022","d MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd/M/yyyy")
Regards
Gokul
thanks for the reply! yes i try it and its work but i still facing a problem there, since uipath auto format the cell as date format
You can try this to convert to required format.Use the following in assign
DateTime.ParseExact("9 December 2022","d MMMM yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("d/M/yyyy")
Cheers
but i have 2 different type of case, 1 case if the day is below 12, it will be date format. but when the day is above 12, it will be general format
When reading from exce as value is genericvalue type it will read any type of data from excel cell without issue.
Is the date format different for both scenarios?
Cheers
Can you try with this expression
DateTime.ParseExact(YourInput.ToString,{"d MMMM yyyy","dd.MM.yyyy"}, System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString(“dd/M/yyyy”)
You can simply add the any number of date formats inside the {“”,“”} and the formats should be separated by comma
The above expression will look into array of string and choose the apt format as per the input string and convert them and return you the output of desired format
Regards
Gokul
i’m sorry but think i ruined the explanation. so this is my case, the default date format of the data is dd/MM/yyyy, but in the excel when the day is below 12, excel will missformated as MM/d/yyyy, for example in the excel it will show as 12/9/2022 but when i click in the value it will show as 9 December 2022. when i try to populate it as generic value it will show as 9 December 2022 wich is totally wrong.
i’m sorry but think i ruined the explanation. So this is my case, the default date format of the data is dd/MM/yyyy, but in the excel when the day is below 12, excel will missformated as MM/d/yyyy, for example in the excel it will show as 12/9/2022 but when i click in the value it will show as 9 December 2022. when i try to populate it as generic value it will show as 9 December 2022 wich is totally wrong.
Can you give try on this expression :
DateTime.ParseExact(YourInput.ToString,{"d MMMM yyyy"," MM/d/yyyy","dd/MM/yyyy"}, System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString(“dd/M/yyyy”)
Regards
Gokul
okay, i will try it, thank you for the reply and have a nice day, sorry for my bad english
You can simply add the any number of date formats inside the {“”,“”} and the formats should be separated by comma.
If not Kindly share the input format only
Regards
Gokul