2 Replies Latest reply on Apr 12, 2016 7:20 PM by AlexCote

    Problem using UpdateValue() and AFTime



      we are trying to add data to a tag in the Pi Server using the AF SDK call UpdateValue, below is the code. What we find is we are unable to create AFValue of the needed date-time (dtTime shown below), AFTime always takes 4 hours behind of the expected date-time. Can you tell me how to execute properly so we do not have an offset?

      Thank you,


        • Re: Problem using UpdateValue() and AFTime
          Kenji Hashimoto

          I guess that your dtTime is DateTime object and utc time.

          In my environment, following works fine.

          var time = new AFTime("2016/4/6 9:00:00");
          var value = new AFValue(100,time);
          pt.UpdateValue(value, OSIsoft.AF.Data.AFUpdateOption.Replace);

          Or if you parse the timestamp as a local timestamp of System.DateTime, it also works. (Of cause you should change "ja-JP" to correct one)

          CultureInfo culture = CultureInfo.CreateSpecificCulture("ja-JP");
          DateTimeStyles styles = DateTimeStyles.AssumeLocal;
          DateTime dtTime = DateTime.Parse("2016/4/6 9:00:00",culture,styles);
          var value = new AFValue(100, dtTime);
          pt.UpdateValue(value, OSIsoft.AF.Data.AFUpdateOption.Replace);

          Could you check above 2 ways?

          1 of 1 people found this helpful
          • Re: Problem using UpdateValue() and AFTime


            "value.Timestamp" is an AFTime which by default shows the UTC time while dtTime (type DateTime) shows local time... To validate, simply look at value.Timestamp.LocalTime.


            Here is the optimized way to write/replace your new value directly to a PI Point.

            pt.UpdateValue(new AFValue(newValue, dtTime), AFUpdateOption.Replace, AFBufferOption.BufferIfPossible);