How to convert string to time and compare with current time?

I have data in excel like this

No problem for read data from excel but my issues i need to do something like this

=> check current time is valid period for Start_bot or not ?

Example :

current_time => 13:00
start_bot => 09:00
stop_bot => 15:30

if this case … program will be start to do tasks…

(Big Thanks for anyone who answer by and example code).
Thanks,

Hi @lovepong66 ,

if want to convert String to time use below code

yourTimeTtring = “18:32”

CDate(“yourTimeTtring”).ToString(“HH:mm”)

which against you want to compare, try to explain with example

Thanks,
Rajkumar

That doesn’t convert it to time. That converts it to date and back to string.

The correct solution is TimeSpan.Parse

In my case … i create .bat file for execute UiPath to autorun script (imagine something like cronjob)
after program execution before to do anything i would like to create function to checking before start the process… see image at below

in details

09:00 and 15:30 just like a config for control time period for my system because i don’t want
my server or my computer to work too hard.

Thanks,

1 Like

grafik

 Now.TimeOfDay >= Cdate("09:00").TimeOfDay And Now.TimeOfDay <= Cdate("15:30").TimeOfDay

As well agreed to use Timespan as we can reduce the code chars
grafik

Now.TimeOfDay >= Timespan.Parse("09:00") And Now.TimeOfDay <= Timespan.Parse("15:30")
2 Likes

Good idea for solved thank you very much

by the way i’m a newbie so i think someone who is now for newbie might be not clear about your
answers so… then i have to attach some detail over here

*** important ***

  1. The datatype of variable must be set to TimeSpan

IF something not clear please download a file.
test_time_period.xaml (7.9 KB)

thank you everyone,
Have a good day

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