3 Replies Latest reply on Feb 8, 2018 4:58 PM by skdesiraju

    AFTimeRange localtime versus UTC time

    skdesiraju

      Hello I am calling a function to that gets PI tag recorded values for a date range. In this case I need the data from 1/1/2017 - 2/1/2017

      var x = funs.GetPiTagRecordedValues("someTag", Convert.ToDateTime("01-jan-2017"), Convert.ToDateTime("01-feb-2017"), true);

       

      This is in the GetPITagRecordedValues function

       

         PIPoint point = PIPoint.FindPIPoint(piserver, TagName);

                 

         AFTimeRange time = new AFTimeRange(startDate, endDate);

        

         AFValues values = point.RecordedValues(time, AFBoundaryType.Inside, null, false, 0);

       

      What I noticed in in AFTimeRange, localTime for start and end dates are 12/31/2016 6:00 pm and 1/31/2017 6:00 pm. It looks like the date is getting converted to the GMT time. Where as the UTC time always shows the right time that we are passing. It looks like it is quering the tag values based off of the localtime and excluding me recorded values between 1/31/2017 6pm to midnight. How can I make the AFTimeRange to take 1/1/2017 instead on -6 hrs?

       

      Thanks in advance for the help

        • Re: AFTimeRange localtime versus UTC time
          Lonnie Bowling

          Hi skdesiraju,

           

          Creating an AFTimeRange should not be converting to UTC. Check the computer you are running the code on to make sure you are doing the conversion correct and what time zone it is set to. Here is something you can try:

           

          AFTime y2k = new AFTime("1/1/2000 12:00:00 AM", CultureInfo.InvariantCulture);

           

          Here is code byte that I use all the time without any issues:

           

                  public void GetPlotValues(DateTime start, DateTime end)

                  {

                      AFTimeRange timeRange;

                      timeRange = new AFTimeRange(start, end);

           

          ....

           

          Lonnie

          • Re: AFTimeRange localtime versus UTC time
            David Hearn

            The problem is that Convert.ToDateTime method returns a DataTime object with its 'Kind' property set to 'Unspecified'. When creating an AFTime from a DateTime and the 'Kind' property is 'Unspecified' then the time is treated as UTC. So you can either create your DateTime objects so that the 'Kind' property is set to 'Local' (e.g. using the DateTime.SpecifyKind method) or you can pass the strings directly into the AFTimeRange constructor instead of a DateTime object. The strings will be interpreted as local time unless they have a time zone indicator in the string.

            1 of 1 people found this helpful