Announcement

Collapse
No announcement yet.

Elapsed minute calculation

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

  • Elapsed minute calculation

    I am trying to work out the elapsed minutes from 4:02am to a device switching off. I know how to save the values to a .ini file. So what I need is to run a event at 4:02 to save this time including the date (or do I need the date ?)
    So how do I save that time, what is the command to retrieve the current date and time ?
    The I can run another event which does the same when the device turns off. Then I can subtract the 2 saved values and that should give me the elapsed time in minutes.
    I know how to save and retrieve from my .ini file. The result will only be a maximum of 75 minutes, never longer so I might not need the date.

  • #2
    Originally posted by mikee123 View Post
    I am trying to work out the elapsed minutes from 4:02am to a device switching off. I know how to save the values to a .ini file. So what I need is to run a event at 4:02 to save this time including the date (or do I need the date ?)
    So how do I save that time, what is the command to retrieve the current date and time ?
    The I can run another event which does the same when the device turns off. Then I can subtract the 2 saved values and that should give me the elapsed time in minutes.
    I know how to save and retrieve from my .ini file. The result will only be a maximum of 75 minutes, never longer so I might not need the date.
    If I'm reading your post right, you don't need to store anything in the ini file because 4:02am is a fixed entity.
    You need an event that's triggered when the device switches off then to calculate elapsed minutes between 4:02am and now (time the device switched off).

    There are a number of ways you can do this but one example is:

    Code:
     Dim dt As DateTime = New DateTime(Now.Year, Now.Month, Now.Day, 4, 2, 0)
     Dim elapsedMins As Long = DateDiff(DateInterval.Minute, dt, Now)
    Paul..

    Comment


    • #3
      Hi Paul, thanks. Hope everything is well ?

      Comment


      • #4
        This is not returning anything, so something is wrong.The variable TotalHotWaterTimeCalc is empty

        Code:
        Sub Main(parm as object)
        
        Dim dt As DateTime = New DateTime(Now.Year, Now.Month, Now.Day, 4, 2, 0)
        Dim TotalHotWaterTimeCalc As Long = DateDiff(DateInterval.Minute, dt, Now)
        
           hs.SaveINISetting("MyVariables", "TotalHotWaterTimeCalc",TotalHotWaterTime, IniFile)
        
        
        End Sub

        Comment


        • #5
          Depending on what you are needing to accomplish, does using a timer help?

          Comment


          • #6
            Yes probably. I have solved the problem in a different way in the meantime, for me its just to learn now what I have done wrong. I like to understand why its not working, helps in future...

            Comment


            • #7
              Originally posted by mikee123 View Post
              This is not returning anything, so something is wrong.The variable TotalHotWaterTimeCalc is empty

              Code:
              Sub Main(parm as object)
              
              Dim dt As DateTime = New DateTime(Now.Year, Now.Month, Now.Day, 4, 2, 0)
              Dim TotalHotWaterTimeCalc As Long = DateDiff(DateInterval.Minute, dt, Now)
              
              hs.SaveINISetting("MyVariables", "TotalHotWaterTimeCalc",TotalHotWaterTime, IniFile)
              
              
              End Sub
              Try:

              Code:
              hs.SaveINISetting("MyVariables", "TotalHotWaterTimeCalc",CStr(TotalHotWaterTime), IniFile)
              TotalHotWaterTime is a number (or long), not a string. The initfile is expecting a string. CStr will do that conversion for you. Note that when retrieving, you will need to do the opposite conversion, using CLng().

              Comment


              • #8
                Yes that did it.

                Comment

                Working...
                X