DateTime how to convert to other format

I extracted a date from a website in the format “25 of jan. of 2021” is there a way to convert this to dd/MM/yyyy format? Thanks

Hi @Daniela_Franco,

Welcome to the UiPath Forum community!

There is an activity in UiPath called Format Date, which can be used to manipulate dates in a DateTime format. You can use a preset format to write to, or you can specify a custom format.
image
image

Try using this activity to format your date. If your date is a string, you can do CDate(StringVar) to convert it to datetime.

2 Likes

That’s not going to work with the format of her string date. Look at it…

“25 of jan. of 2021”

She will probably have to manually parse that to get the day (left, 2) and the month (substring) and the year (right, 4) then generate a “New Date…” from it.

1 Like

Oh yes, I see. Thanks @postwick.

In that case @Daniela_Franco, manipulate the date as @postwick has suggested, I imagine you’d need three separate variables for the day, month and year that you can join into one variable.

Day = Left(YourVar, 2)
Month = YourVar.Substring(5,6).Trim.Replace(".","") (I don’t often use Substring so there may be a better way to get the month)
Year = Right(YourVar, 4)

NewVar = Day + "/" + Month + "/" + Year

And then format NewVar with Modify Date
image

1 Like

NewVar should be a datetime variable, and to create it from day/month/year you use parse or parsexact to convert the string values into a datetime. For the substring, just take the 3 characters you need. Why get other things then replace them out?

1 Like

Hi @Daniela_Franco

As mentioned above, the best way to start is to convert your string to a variable of type DateTime. You can do that in multiple ways.

I think the simplest might be with the TryParse like so:
image

DateTime.ParseExact(stringDate,"dd \o\f MMM. \o\f yyyy",System.Globalization.CultureInfo.InvariantCulture)

The way to then print that variable to a string in your desired format has already been explained above.

1 Like