How can I assign time duration activity

Duration time” The duration of one operation in addition to the previous operations”: Create a new variable of datetime type and assign it as dtStartTime = DateTime.Now
And calculate (“time difference”) how long it takes by subtract dtStartTime from DateTime.Now and insert the data into the field with the format “HH:mm:ss”.

@Mohammad_Allan

timeDifference = (DateTime.Now - dtStartTime).ToString("hh\:mm\:ss")


I put message box for some delay. so simply skip that message box

we do have other options for such measurements

have a look e.g. at

Assign activity:
timeDifference = DateTime.Now.Subtract(dtStartTime)

Assign activity:
timeDifferenceString = timeDifference.ToString(“HH:mm:ss”)

Make sure to declare the variables timeDifference and timeDifferenceString of type TimeSpan and String , respectively, in the Variables pane of UiPath Studio.

Hi @Mohammad_Allan

Try this:

Assign: dtStartTime = DateTime.Now    (DataType: System.DateTime)

\\Perform your operation

Assign: timeDifference = DateTime.Now - dtStartTime     (DataType: System.TimeSpan)
Assign: formattedTimeDifference = timeDifference.ToString("hh\:mm\:ss")   (DataType: System.String)

Hope it helps!!

If it is mainly for debugging and troubleshoot purposes, a simple logmessage (if needed to store in orchestrator) or witeline (if only in studio) will suffice. If needed one before and after the measurable activity.
Each console log already has a timestamp. Just enable the little clock icon top left of your output window in the studio (‘Show Timestamps’)

Hi @Mohammad_Allan

The below image will give you better understanding:

Assign-> dtStartTime = DateTime.Now   (DataType: System.DateTime)
         
        \\Perform your operation

Assign-> timeDifference = DateTime.Now - dtStartTime   (DataType: System.TimeSpan)

Assign-> formattedTimeDifference = timeDifference.ToString("hh\:mm\:ss")    (DataType: System.String)

Log Message/Message Box-> formattedTimeDifference

Regards

1 Like

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