Pervasive
Sign in | Join | Help
in

How to generate native btrv timestamp values

Last post 07-03-2008 8:13 AM by Werner. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-02-2008 5:36 AM

    How to generate native btrv timestamp values

    Hello !

    I have to generate valid btrieve timestamp values (using native btrv, not via SQL).

    The reference manual says (A-28) : "The value is stored internally as a TIMESTAMP MicroKernel key, an 8-byte long field that contains the complete date and time value converted to the fractions of seconds that timestamp precision specifies .."

    But don't know some more things:

    1.  How/Where can I adjust timestamp precision ? In PCC the precision field for timestamp is greyed out

    2. Since when do the seconds of timestamp values count ? 

     Werner

     

  • 07-03-2008 5:35 AM In reply to

    • Gordon
    • Top 100 Contributor
    • Joined on 08-30-2007
    • Delft, The Netherlands
    • Posts 53

    Re: How to generate native btrv timestamp values

    I just added  '03-07-2008 11:49:07' to a table and then read it back as an integer with value 633506753470000000

    There appears to be a default precision at 10^7 but I have no clue where this comes from. Dividing by 10,000,000 results in 63350675347 as the number of seconds which is way too large to be Unix timestamp. As this is just a variation on Julian date with an extension for time I figured I should devide this by 60*60*24 to convert it to number of days, resulting in the number 733225.41. Feeding this into MS Excel returnes '02-07-2007 09:49' which is exactly 367 days short of the time I started out with (the time difference is caused by me being in CEDT which is +2:00 from UTC).


    Making timestamp value the number of 1/10th microseconds since 01/01/1901 00:00:00

  • 07-03-2008 8:13 AM In reply to

    Re: How to generate native btrv timestamp values

    Thank you very much for your reply, which led me to the following solution:

    733255 is not the number of days since 01/01/1901 00:00:00 but the number of days since 01/01/0001; so I figured out the following  (C++, Windows):

    time_t osBinaryTime; // C run-time time (defined in <time.h>)

    time( &osBinaryTime ) ; // Get the current time from the operating system.

    // osBinaryTime now contains number of seconds since 01.01.1970 00:00:00

    __int64 BtrvTimestamp;

    BtrvTimestamp=719162L; // number of days between 01.01.0001 and 01.01.1970

    BtrvTimestamp*=3600L*24L; // now in seconds

    BtrvTimestamp+=osBinaryTime; // add seconds since 01.01.1970 00:00:00

    BtrvTimestamp*=10000000L; // convert to 1/10-Micro-seconds

     

Page 1 of 1 (3 items)
© 2008 Pervasive Software Inc. All Rights Reserved.