The string 'MMMM/dd/yyyy' was not recognized as a valid DateTime. There is an unknown word starting at index '0'

Hi, anyone can advice me?
Im trying to convert the string ‘ENE/15/2022’ to datetime, but as you can see the month is in spanish. I already tried this: Convert.ToDateTime(A.Split("-"c)(0).Trim,CultureInfo.GetCultureInfo(“es-ES”)), and also with Parse and ParseExact methods but it still dont work.

Hellppp

Hi @kmilo_de_los_santos
Welcome to UiPath Community

for parseExact try MMM/dd/yyyy instead @kmilo_de_los_santos

@kmilo_de_los_santos Check this below attached workflow,
Uipath_ConvertDate_SpanishToEnglish.xaml (6.7 KB)

Pass your input date string in arguments as shown in below screenshot,

Hope this may help you :slight_smile:

@kmilo_de_los_santos If you just want to convert a Spanish string to datetime type then check this updated workflow below,
Uipath_ConvertDate_SpanishToEnglish.xaml (10.7 KB)

Hope this might help you :slight_smile:

Hi @kmilo_de_los_santos

Welcome to Community!

Try with this expression

DateTime.ParseExact("ENE/15/2022",{"MMM/dd/yyyy","MMMM/dd/yyyy"},System.Globalization.CultureInfo.GetCultureInfo("es-ES"),System.Globalization.DateTimeStyles.None).ToString("MMM/dd/yyyy")

Regards
Sudharsan

Hello @kmilo_de_los_santos
Try this

DateTime.ParseExact("ENE/15/2022","MMM/dd/yyyy",System.Globalization.CultureInfo.GetCultureInfo("es-ES")).ToString("MMM-dd-yyyy")

DateTime.ParseExact("ENE/15/2022","MMM/dd/yyyy",System.Globalization.CultureInfo.GetCultureInfo("es-ES")).ToString("MMMM-dd-yyyy")

image

Hello @Sudharsan_Ka thanks for your answer, I tried with that method but still getting the same error, I checked the imports and i have the system.globalization ¿There is another one I need to run the activity correctly?

Can you check the input and see if you have any empty spaces with it @kmilo_de_los_santos ?

hello @Gokul_Jayakumar and @jack.chan, I also tried with the method you write with just copy and paste that but I am still getting the error as in the case of the code from Sudharsan_Ka. Can you help to do it with that method? I dont know which dependency or error I am missing.

This is the log message:

Source: Write Line

Message: String ‘ENE/15/2022’ was not recognized as a valid DateTime.

Exception Type: System.FormatException

System.FormatException: String ‘ENE/15/2022’ was not recognized as a valid DateTime. at System.DateTimeParse.ParseExactMultiple(ReadOnlySpan1 s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style) at System.DateTime.ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style) at Namespace_30cf.Main_Expressions.Main_Expressions_TypedDataContext2_ForReadOnly.__Expr3Get() at Namespace_30cf.Main_Expressions.Main_Expressions_TypedDataContext2_ForReadOnly.ValueType___Expr3Get() at Namespace_30cf.Main_Expressions.InvokeExpression(Int32 expressionId, IList1 locations, ActivityContext activityContext)
at System.Activities.Expressions.CompiledExpressionInvoker.InvokeExpression(ActivityContext activityContext)
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Thank you very much @Manish540, it worked as expected and the instructions in the document are perfect.

I tried with your method and this was my output:


what are you using .net project file or C# ?@kmilo_de_los_santos

I am using a .net project

Hi @kmilo_de_los_santos,

Add dot ‘.’ after ENE (ENE.) because of that you are getting invalid format.

I have attached a workflow which gives you the Spanish months.

I have two machines. On one machine I have no issues but in another I am getting the same error as you are.

As you can see for every Spanish month it ends with dot.

image

Uipath_ConvertDate_SpanishToEnglish.xaml (10.9 KB)

1 Like

Thank you very much @KirtiIyer , indeed that was the cause of the error.

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