Data Management
PI System
Tech

Handling Midnight Timestamps in the PI System

Learn how to manage and correct midnight timestamps formatted as 24:00:00 in OSIsoft's PI System through datetime extraction and manipulation.

Roshan Soni

4 min read

Handling Midnight Timestamps in the PI System

In the realm of industrial data systems, accurate timestamp management is crucial, particularly in systems like OSIsoft's PI System, where data accuracy can directly impact decision making and operational efficiency. However, handling timestamps that mark the transition from day to day—specifically midnight—can sometimes present challenges.

A common issue arises when dealing with external data sources that format midnight as 24:00:00 instead of the conventional 00:00:00. This discrepancy can lead to errors in the PI System, such as "argument out of range" exceptions, because PI’s DateTime data type does not support a 24:00:00 timestamp.

Understanding the Problem

The challenge usually surfaces in environments where data is periodically logged—for instance, every 15 minutes—and midnight is logged as 24:00:00. This format might seem intuitive within certain systems or rational from a human perspective as it indicates the end of a day, but it is not a time format that is supported by PI’s datetime handling functions.

For example, data arriving in the format "yyyyMMddhhmmss" might translate midnight of January 2nd, 2021, into the string "20210102240000", when it should be "20210103000000" for January 3rd, 2021, 00:00:00.

Solutions to the Midnight Timestamp Dilemma

Extracting and Reconstructing Time

To resolve this issue, the incoming timestamp should be manipulated to fit the supported format. The solution entails extracting the date and time portions separately from the timestamp string and then combining them back to form a valid DateTime object.

Step-by-Step:

  1. Extract the Date and Time:

    • Use string manipulation functions to extract the date portion using a function like LEFT, that takes the first 8 characters of the timestamp for the date.
    • Similarly, extract the last 6 characters for the time using a RIGHT function.
  2. Check for 24:00:00:

    • If the time portion is "240000", adjust it to "000000" and increment the date by one day.
  3. Combine the Date and Time:

    • Combine the two components back into a single DateTime object, which can then be processed by the PI System.

Sample Code

Here's a simplified example of how this can be implemented in a PI UFL interface:

[FIELDS]
FIELD(2).NAME="Master_TimestampStr"
FIELD(2).TYPE="String"
FIELD(9).NAME="Master_Date"
FIELD(9).TYPE="DateTime"
FIELD(9).FORMAT="yyyyMMdd"
FIELD(10).NAME="Master_Time"
FIELD(10).TYPE="Time"
FIELD(10).FORMAT="hhmmss"

Master_TimestampStr=["*;(*);*;*;*;*;*;*;*"]

Master_Date = LEFT(Master_TimestampStr,8)
Master_Time = RIGHT(Master_TimestampStr,6)

IF Master_Time = "240000" THEN
    Master_Time = "000000"
    Master_Date = ADD_DAYS(Master_Date, 1)
ENDIF

Master_Timestamp = Master_Date + Master_Time

StoreInPI(TagName,,Master_Timestamp,Value1,0,,)

Conclusion

While encountering a midnight-as-24:00:00 issue might initially appear as a simple formatting hiccup, the implications can be significant in data accuracy and system function. By implementing a methodical approach to timestamp manipulation, users can effectively align their data influx with PI System’s requirements, ensuring smooth and error-free data logging.

Tags

#PI System
#Data Integration
#DateTime Handling
#Time Formatting

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Developing Expertise in PI System and Related Technologies: A Comprehensive Training Roadmap

This blog outlines a comprehensive training roadmap for developing expertise in the PI System and related technologies. Structured over four weeks, the program covers essential technologies like the PI System, Asset Framework, and various APIs, providing a strong foundation for data management and analytics.

Roshan Soni

Traversing an AF Database Hierarchy to Count All Elements Using OSIsoft AF SDK

Learn how to use the OSIsoft AF SDK in C# to traverse an AF database and count all elements within its hierarchy. This blog post provides a comprehensive guide with code examples for connecting, traversing, and counting AF elements.

Roshan Soni

A Beginner's Guide to Learning the OSIsoft PI System

Unlock the power of real-time data management and analytics with OSIsoft PI System. This beginner's guide provides a structured learning path and key resources to help you effectively learn the PI System.

Roshan Soni