I am using
DateTime.ParseExact(getVal.ToString,“yyyy-MM-dd hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
to convert my generic variable type to DateTime.
getVal is my variable which I am getting from an excel file.
The value is in a format of yyyy-MM-dd hh:mm:ss
For eg - 2022-03-01 16:26:53
I am not able to resolve the error. Please help.
Thanks in advance.
1 Like
Hi @Nikhil_kathpalia ,
Could you give this a try?
DateTime.ParseExact("2022-03-01 16:26:53","yyyy-MM-dd HH:mm:ss",Nothing).ToString("HH:mm:ss")
DateTime.ParseExact("2022-03-01 16:26:53","yyyy-MM-dd HH:mm:ss",Nothing)
Kind Regards,
Ashwin A.K
1 Like
This just gives me a compiler error
Nikhil_kathpalia:
yyyy-MM-dd hh:mm:ss
Hi
Welcome to UiPath forum
Try with this expression
Datatime.ParseExact(strinput.ToString.SubString(0,10).Trim, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture)
Output will be of DateTime
If you need in string of specific format
Stroutput = Datatime.ParseExact(strinput.ToString.SubString(0,10).Trim, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)
I want to suggest you one thing
You are almost right…
The only thing is timestamp
It’s in 24 hours format then hours should be in HH
But you have mention as hh in that DateTime expression
Change it to HH and give a try or
Try with the above suggestion
It should be fine
For more details on DateTime in UiPath
Hi All,
My recent post on datatable [All About Datatable- UiPath] (https://forum.uipath.com/t/all-about-datatable-uipath/386445 ) was received well in forum with great feedbacks and many suggested to provide some tutorial on topics which are discussed often in our forum
In regards to that I would like to share the commonly used expression for DATETIME conversion
Let’s get started one by one
1. Get Current Date in string format
Datetime.Now.ToString()
(Output - string type - “dd/MM/yyyy hh:mm…
Cheers @Nikhil_kathpalia
2 Likes
Gokul001
(Gokul Balaji)
March 14, 2022, 11:10am
5
HI @Nikhil_kathpalia
Try this expression
CDate(Inputstring).Tostring("yyyy-MM-dd HH:mm:ss")
Regards
Gokul
DateTime.ParseExact(“2022-03-01 16:26:53”,“yyyy-MM-dd HH:mm:ss”,Nothing) This actually works when I put the string on my own. But when I am getting the string from my excel file, it is not working
can you tell what I am possibly doing wrong?
Hi @Nikhil_kathpalia ,
We would ask you to Perform a Debug and Check the values of the Excel in the Immediate panel, or we could Check it with a Write Line
Activity.
This way we can know if there are other formats as well included in the dates.
1 Like
Gokul001
(Gokul Balaji)
March 14, 2022, 11:18am
8
Hi Can you share the sample Input Excel file @Nikhil_kathpalia
This actually worked, I changed hh to HH and it worked
Thanks a ton!!
Thankyou everyone who helped!! I was stuck at this since yesterday and this is my first time using UIpath community.
1 Like
Glad it got resolved
Cheers @Nikhil_kathpalia
1 Like
system
(system)
Closed
March 17, 2022, 11:56am
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.