Convert string to date

Hello,

I am trying to convert a string (which is a date I used data scrape to capture) of Nov 21, 2019 to 21/11/2019. I then want to compare it with today’s date to see if it matches.

Does anyone know how to convert the string to date format?

Thank you!

1 Like

Fine
this expression would help you on that
if the input is
str_input = “Nov 21, 2019”
then to compare with todays date in IF condition with this expression
Datetime.ParseExact(str_input,“MMM dd, yyyy”,system.Globalization.CultureInfo.InvariantCulture).Date.ToString.Equals(Now.Date.ToString)

and to get that as a datetime variable
datetime_var = Datetime.ParseExact(str_input,“MMM dd, yyyy”,system.Globalization.CultureInfo.InvariantCulture)

Cheers @Cormac

1 Like

Hi @Palaniyappan - Thanks for your response.

Is the below correct then to get the datetime as a variable? It won’t validate for me.

my variable is called confirmationdate. Am I substituting ‘datetime_var’ with my variable?

image

image

1 Like

you were almost done
yah ensure that confimationDate is a variable of type System.Date.Datetime
we can search that in Browse Type in variable panel under the column Datatype
and also in the expression you missed out one y along the year
like this
Datetime.ParseExact(str_input,“MMM dd, yyyy”,system.Globalization.CultureInfo.InvariantCulture)

Cheers @Cormac

1 Like

Thanks again!

To convert the variable (which is a string) System.Date.Datetime should I do the following?

Also the variable is a string because when I capture it with data scraping I am removing some characters at the end of the string

image

like this buddy, not with assign activity

we can find this type in BROWSE FOR TYPE in the Variable type column
Cheers @Cormac

1 Like

Sorry for the stupid questions - but if I change the variable to System.DateTime my other Assign activities where I use the variable wont validate. For example I am assigning value from a data table to that variable and then removing some characters at the end and then trying to convert that string to a sate format - like the below screen shots

image

image

image

Fine
the sequence be like this
–hope you have a datatable variable ready
–then inside the FOR EACH ROW activity use a ASSIGN activity like this
str_input = row(“Column1”).ToString.Substring(0,12)
where str_input is a variable of type string

–now use a ASSIGN ACTIVITY like this
confirmationDate = Datetime.ParseExact(str_input,“MMM dd, yyyy”,system.Globalization.CultureInfo.InvariantCulture)

where confirmationDate is a varaible of type System.Date.Datetime

then to compare with todays date
use IF activity with condition like this
Datetime.ParseExact(str_input,“MMM dd, yyyy ”,system.Globalization.CultureInfo.InvariantCulture).Date>Now.Date
if true it will go to THEN part or goes to ELSE part

Cheers @Cormac

1 Like

Thanks so much! That worked!!

1 Like

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