Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to time events?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to time events?

    Hi NT,

    I'd like simply to calculate the time ( in secs ) between two events, but I'm not sure about which is the best, simple and reliable method.

    I've seen the typical example:
    DateTime.Now.Ticks - Time[0].Ticks

    Can I do the same but getting the seconds of difference? I'm not used to manage Time in C#, so I don't know what a tick means in time.

    Any help would be great


    Thanks in advance

    #2
    Hello,

    Thank you for the question.

    One way of doing this would be using DateTime.Subtract, here is a simple example that checks the amount of seconds between 1 bar ago and the Current computer time:


    Code:
    if(Historical) return;
    DateTime timeA = DateTime.Now;
    DateTime timeB = Time[1];
    
    int seconds = timeA.Subtract(timeB).Seconds;
    Print(seconds);
    Here is more information on DateTime and TimeSpan, TimeSpan is the object Subtract returns.

    Represents an instant in time, typically expressed as a date and time of day.



    I look forward to being of further assistance.

    Comment


      #3
      2 questions:

      - That difference in seconds would it be an integer value, right ? or would it be a Time structure data?

      - Let's suppose that we have a difference > 60 secs, your procedure would give a value > 60 or other form?

      Comment


        #4
        Hello,

        For a total time in seconds greater than 60 seconds, you could use the TotalSeconds property, for a complete list of options, please refer to the MSDN documentation on TimeSpan.

        here is a simple test you can do on your end to see that this produces 180 seconds for 3 minutes of a TimeSpan:

        Code:
        TimeSpan span = new TimeSpan(0, 3, 0);
        Print(span.TotalSeconds);
        The Property would be an int type, the span would be your TimeSpan object.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X