Epoch time to Time date convert

Forum Home Forums Understanding the Software Using Formulas Epoch time to Time date convert

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #12749
    emhatek
    Participant

    Dear All,
    my channel is connected to the OPC DA that contain the epoch value. however we want to display it as time date format.
    Does anyone success to create formula that can convert the epoch time to time date format.
    please advise if any.

    thanks & regards
    Emha

    • This topic was modified 9 months, 3 weeks ago by emhatek.
    #12751
    manjey73
    Participant

    What is time in Epoch format ?
    Are you talking about Unix Time?

    • This reply was modified 9 months, 3 weeks ago by manjey73.
    #12753
    manjey73
    Participant
    #12754
    manjey73
    Participant

    And in order to convert DateTime to the channel value, you need to add DateTime.ToOADate()

    #12756
    Mikhail
    Moderator

    Hi,


    @emhatek
    , what version of Rapid SCADA do you use?

    #12760
    emhatek
    Participant

    Hi Manjey,
    thanks for your reply,
    epoch mean UNIX timestamp value in UTC.
    OPC channel value type is epch unix, and will be displayed in the HMI page in datetime format.

    #12761
    emhatek
    Participant

    Hi Mikhail,
    my rapid scada is V6

    #12762
    emhatek
    Participant

    Dear All,
    currently i’m success to convert UNIX time to datetime format as Manjey Advice. below my formula that add to scrip database.

    public static double UnixTimeStampToDateTime(double unixTimeStamp)
    {
        // Unix timestamp is seconds past epoch
        DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
        dateTime = dateTime.AddSeconds( unixTimeStamp );
        return dateTime.ToOADate();
    }
    #12764
    Mikhail
    Moderator

    Also possible

    dateTime = DateTimeOffset.FromUnixTimeSeconds((long)unixTimeStamp).ToUniversalTime();
    
    #12777
    emhatek
    Participant

    Hi Mikhai,
    let me try and thanks for your advise.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.