My question seems simple to solve however I haven’t been lucky so far. I’m using a Get Text activity to get the following from a web page. Since I only want the date, I use String.Substring(18).TrimEnd successfully.
But afterwards I want to convert this to an actual date format, so I can check if it is located between two other dates. The problem is when I do DateTime.ParseExact(String, “yyyy/MM/dd”, System.Globalization.CultureInfo.InvariantCulture), the date comes back in dd/MM/yyyy, and I need it in the original format.
Thanks a lot
You have to change the format after this, what you are currently doing.
You can use this statement:
for example you save the result date after trim in variable: dateWeb
Please watch also this video to learn more about converting the date formatting: UiPath | Date Formatting | Convert date to String | Get date format | yyyy.MM.dd | dd.MM.yyyy - YouTube
Thank you. But then won’t this result in a string? I would like to get the final result in a Date format so I can compare with other dates. Is there a way to do this?
You have then to convert the string variable to date.
Check below for your reference
Hope this may help you
Have you tried - Datetime.Parse(yourVariable).tostring(“yyyy/MM/dd”).
This will give your date in the same format.
He needs the variable to be a date?
datetime variables don’t have a format. The only time you see a format is when you output it as a string.
You control the format in the ToString parameter:
DateTime.ParseExact(String, “yyyy/MM/dd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)
DateTime.ParseExact(String, “yyyy/MM/dd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd_MM_yyyy”)
The “yyyy/MM/dd” you’re passing to ParseExact is telling it how to read the input string, not telling it how to store the datetime value.