Timespan help please!

Hi,

I’m trying to learn how Timespan (in C#) works, but the online resources I’ve viewed so far have really confused me. I was wondering if someone could walk me through a really simple scenario?

Say for example, I had a ‘StartTime’ (I’m guessing I use an ‘Assign’, using System.DateTime.Now), and then some time later, I get a ‘LaterTime’ (again, using System.DateTime.Now). Would I then use Timespan to calculate the difference between the two times? If so, how would I do this? And would the ‘StartTime’ and ‘LaterTime’ variables be of type ‘Object’, or would they be ‘DateTime’?

Sorry if these are really silly questions, but I’m SO confused!

Thanks

Hi,

Can you check the following sample?

Sample20230922-6LCS.zip (2.5 KB)

Regards,

,

Hi @paulparkes

If you need time as output

StartTime=System.DateTime.Now

LaterTime =System.DateTime.Now

timeDifference = endTime.Subtract(startTime)

If you need only time difference as output

You can try this

timeDifference=timeDifference.ToString(“hh:mm:ss”)

Thank you for this. I’ve almost got it working, but I don’t have the TimeSpan variable type listed; when I browse for it, it’s not available. Is there a plugin or something that I might be missing?

you can search like this you can find the time span variable type

@paulparkes

image

I don’t have it

you can directly type "timespan " or “system.timespan”

you can see my screenshot
image

@paulparkes

That’s got it, thanks!

@paulparkes

cheers …:slight_smile:

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