Converting worded date (string) to date

I am trying to convert a word date to a datetime.

My variable ‘scrapedDate’ is a string and it is ‘2nd January 2020’
My datetime variable is ‘newDate’ and its assigned to ‘Date.parseexact(scrapedDate,“dd/MMMM/yy”,system.globalization.cultureinfo.invariantculture)’.

It’s saying the string isn’t a valid date time. Whenever I used ‘02012020’ the conversion works ok so I know the problem is with the string.

Any suggestions?
Thanks

Hi
welcome to uipath community
kindly try with this expresion
if the input is in a variable named str_input
then
use a assign activity like this
str_input = System.Text.RegularExpressions.Regex.Match(Split(str_input.ToString," “).(0).ToString.Trim,”(\d).“).tostring.PadLeft(2,cchar(“0”))+” “+Split(str_input.ToString,” “).(1).ToString.Trim+” “+Split(str_input.ToString,” ").(2).ToString.Trim

so now we will be ggetting as
str_input = “02 January 2020”

now use a assign activity like this
str_output = Datetime.ParseExact(str_input.tostring,“dd MMMM yyyy”,system.globalization.cultureinfo.invariantculture).tostring(“dd/MM/yyyy”)
or

to use as a datetime variable
date_output = Datetime.ParseExact(str_input.tostring,“dd MMMM yyyy”,system.globalization.cultureinfo.invariantculture)

where date_output is a variable of type system.datetime

Cheers @Vicky_Fegan

You only need this:

MyDate = Datetime.ParseExact(“02 January 2020”,“dd MMMM yyyy”,system.globalization.cultureinfo.invariantculture)

Hi,

Hope this helps you.

newDate = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Replace(scrapedDate,"(?<=\d+)[a-z]+(?=\s+)",""),"d MMMMMM yyyy",nothing)

Regards,

I am scraping the text from somewhere and it scraps in as ‘2nd January 2020’

just put your text variable where i put the text…

It’s still saying the string isn’t a valid date time

Hi,

Does you string data has single quote?
if so, can you try the following?

DateTime.ParseExact(System.Text.RegularExpressions.Regex.Replace(scrapedDate.Replace("'","").Trim,"(?<=\d+)[a-z]+(?=\s+)",""),"d MMMMMM yyyy",nothing)

Main.xaml (5.4 KB)

Regards,

1 Like

It’s saying some of it has to be identified

you have everything right there only this part is wrong: dd/MMMM/yy and need to be dd MMMM yyyy

It’s saying that the string isn’t valid

If the string is really this 2nd January 2020 then it should not say that… i tested myself… maybe you have an extra space somewhere…

here you go with a xaml
datett.zip (2.0 KB)

Cheers @Vicky_Fegan

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