5 Replies Latest reply on Apr 18, 2010 8:57 PM by zglenskij

    API time conversion from Long Int to VBA Date

    zglenskij

      How do I convert a the time(timedate=1267864200) returned from

      Sub GetSnapshot()

      Dim pt As Long
      Dim rval As Variant
      Dim iStat As Long
      Dim timedate As Long
      Dim wait As Long
      Dim RetVal As Long

      pt = 59

      RetVal = pisn_getsnapshot(pt, rval, iStat, timedate)

      End Sub

      to a VBA Date, for example 3/2/2010 7:30:00 AM

        • Re: API time conversion from Long Int to VBA Date

          Hi Jennifer, The vCampus program doesn't support PIAPI discussions (or something along those lines), so probably a candidate to ask TechSupport.

           

          To give you an idea, you need to use the PI Time API functions (prefixed "pitm_") to get a string representation that you can use to form a date object.

           

          On the same topic, any reason you are still using PIAPI and not moved to PISDK?

            • Re: API time conversion from Long Int to VBA Date
              Daniel Takara

              Rhys @ RJK Solutions



              To give you an idea, you need to use the PI Time API functions (prefixed "pitm_") to get a string representation that you can use to form a date object.


              Yes, this would be the pitm_formtime function.

               

              Alternatively, you may consider doing the conversion calculation yourself. If a certain int32 timedate variable contained the timestamp of the snapshot event retrieved by pisn_getsnapshot, we could get the corresponding Date value with the following calculation:

              CDate(#1/1/1970# + CDbl(timedate / 86400))

              If you are using VBA for Excel and your intention is to use an Excel sheet as the final output, you may also use the pitime2xl function available in %PIHOME%\INCLUDE\piutil.bas :
              '-------------------- convert PI time to Excel time
              ' 1-jan-1970 is 25569 on MS Windows, and there are 86400 seconds in a day.
              Function pitime2xl(pitime As Long) As Double
                 pitime2xl = CDbl(pitime) / 86400 + 25569
              End Function

              Anyhow, as Rhys already asked, is there any reason why you are using the PI API instead of the PI SDK?

                • Re: API time conversion from Long Int to VBA Date
                  zglenskij

                  It's an existing API application.  The customer is not interested in changing to SDK right now.  Perhaps in the near future.

                   

                  This is more a VBA question: 

                   

                  I have

                   

                  dtDate as Date (value is like this 3/2/2010 7:30:00 AM), and

                   

                  stime = Format(dtTime, "DD-MMM-YY hh:mm:ss") as string (value is like this "02-Mar-10 07:30:00"), and

                   

                  timedate as long (value is like this 1268123400),

                   

                  and timestring as string (value is like this "3/9/2010 8:30:00 AM").

                   

                  [dtDate and stime are the same & timedate and timestring are the same]

                   

                  I want to check that timedate/timestring does not equal dtDate/stime, regardless of the time.  I am interested in just the date.  The problem is I cannot get timedate into a VB Date datetype in order to compare.  I think comparing strings opens up too much room for error, due to date formatting.