Error Formato Fecha

Hola , favor su orientacion, tengo la version nueva de UIPATH y al intentar hacer un cambio de fecha a una variable “Mivariable” ( de tipo String) la cual posee el contenido “11/22/2022 00:00:00” y al aplicar :
DateTime.ParseExact(Mivariable.ToString, “MM-dd-aaaa”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“yyyy-MM-dd”)

me arroja:
Assign: String ‘11/21/2022’ was not recognized as a valid DateTime.

Alguna idea?

Try this expression @Fernando_Montano

In the expression you have use aaaa instead of yyyy

DateTime.ParseExact(Mivariable.ToString, “MM-dd-yyyy”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“yyyy-MM-dd”)

Hi @Fernando_Montano

How about this expression?

DateTime.ParseExact(Mivariable.ToString, “MM-dd-yyyy hh:mm:ss”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“yyyy-MM-dd”)

No funciona, arroja mismo Error :
Assign: String ‘11/20/2022 00:00:00’ was not recognized as a valid DateTime.

Hi @Fernando_Montano

Check out this expression

DateTime.ParseExact("11/20/2022 00:00:00","MM/dd/yyyy hh:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString("yyyy-MM-dd")

Regards
Gokul

grafik

@Fernando_Montano

image

cuando ingreso el nombre de la variable me arroja error. Necesito que la expresión sea con “Mivariable”

Have you tried with this expression ? @Fernando_Montano

image

image

image

asi se ve

do not quote the var name
CDate( Mivariable.ToString).toString("yyyy-MM-dd")

we also recommend to use the debbuging paneld for RnD and Prototyping
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

1 Like

Hi @Fernando_Montano

Can you print the fechaConsulta in the log message and share the screenshot?

Try to use .Tostring.trim

DateTime.ParseExact(fechaConsulta.Tostring.Trim,"MM/dd/yyyy hh:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString("yyyy-MM-dd")
1 Like

Funciona!
Muchas gracias @ppr and @Gokul001 !!!

funcionó con :
CDate( Mivariable.ToString).toString(“yyyy-MM-dd”)

y con :
DateTime.ParseExact(fechaConsulta.Tostring.Trim,“MM/dd/yyyy hh:mm:ss”, System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“yyyy-MM-dd”)

GRACIAS!

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