Skip to main content
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

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni