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
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.
Try using this activity to format your date. If your date is a string, you can do CDate(StringVar) to convert it to datetime.
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.
Oh yes, I see. Thanks @postwick.
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
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?
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:
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.