Convert String to Date error (HELP)

Hello!

I am trying to convert my string to date but i get this error in the image

Capture

Hi @gustavo.souza

Use the below one in the place of StrVariable pass your String variable.

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

Note - In the place of dd/MM/yyyy you can change the format.

Hope it helps!!

Hi @gustavo.souza

Try this

DateTime = DateTime.ParseExact(dateString, format, System.Globalization.CultureInfo.InvariantCulture)

@gustavo.souza

string dateFormat = “MM/dd/yyyy”;

// Convert string to DateTime using DateTime.ParseExact
DateTime dateValue = DateTime.ParseExact(dateString, dateFormat, CultureInfo.InvariantCulture);

Hi @gustavo.souza

According to our System Date Time format is MM/dd/yyyy. So It will give you an error.

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

(Datatype: System.DateTime)

Regards,

Now return this error:

@rlgandu @Parvathy @lrtetala

@gustavo.souza

You are storing the Datetime in a Variable right,
Then Change the variable type to System.DateTime
image

Hope you understand!!

@gustavo.souza

Variable type as System.DateTime

Hi @gustavo.souza

try this:
DateTime.ParseExact(StrVariable, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)

In place of dd/MM/yyyy give the time format that you are getting.

The output variable type is DateTime

@gustavo.souza

I change for this and return to first error…

Capture

I read the data in Excel and use output data table to change datatable to string

DataVencimento has a newline at the end, that’s why the end single quote is on the next line of the Output.

1 Like

how do i solve this?

Get rid of the newline at the end of the string.

DataVencimento.Replace(VbCrLf,“”)

1 Like

Now I need to know the name of the month, do you know any way I can do it?

In Syntex in the place of dd/MM/yyyy
MM give MMM to get like Jan,Feb
If you give MMMM to get like January, February.

Hope it helps!!

1 Like

When I change from dd/MM/yyyy to “MMMM” it gives me this error:

Assign: String ‘07/17/2023’ was not recognized as a valid DateTime.

But with dd/MM/yyyy it works…

Make your .ToString…

.ToString(“MMMM”)

1 Like

Thats work!! Tks

And to change to other language?

i try this

DateTime.ParseExact(newlineClean, “dd/MM/yyyy”, System.Globalization.CultureInfo.CreateSpecificCulture(“pt-BR”)).ToString(“MMMM”)

but not work :frowning: