Convert a string to Date time variable

I have a string variable “DateDoc” result the clipboard, this is the date “09.21.2019 11:18:38” the date will always change. I need to translate a string variable into a date format, minus 1 second. Tell me how to do this? Visiul Basic

2 Likes

Hi ,

You can use the below code to reduce one second from the given string

(DateTime.ParseExact(“09.21.2019 11:18:38”,(“MM.dd.yyyy hh:mm:ss”),system.Globalization.CultureInfo.InvariantCulture).Second-1).ToString

you can do one more way also
1.create a string variable and store your 09.21.2019 11:18:38 in that string variable
2.in assign activity you can create DateTime variable and use CDate(string)
3.(DateTimeVar.Second-1).toString

Hi!
The date from the clipboard will change. I can not use only this date. Next, I need to paste the fully copied date minus one second into another document. I tried using your code, but it only inserts 37 into the document.

image

1 Like

@NastyaL Welcome to uipath community try below solution and let me know

DateDoc = “09.21.2019 11:18:38”

Datetime.ParseExact( DateDoc,“dd.MM.yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).AddSeconds(-1).ToString(“dd.MM.yyyy hh:mm:ss”)

“AddSecond” not a member “Date”

1 Like

Hi
Welcome to uipath community
You were almost done
The expression be like this
Datetime.ParseExact( DateDoc,“dd.MM.yyyy hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).AddSeconds(-1).ToString(“dd.MM.yyyy hh:mm:ss”)

Cheers @NastyaL

2 Likes

Win! thank you very much

2 Likes

@NastyaL Add Seconds(-1)

Cheers @NastyaL

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