TimeStamps

Chapter Updated 08/18/25




Class xbTimeStamp - Time Stamp Class.

The xbTime class is used for storing and manipulating time stamp values.

  • The time is stored internally in a 8 byte double in big endian format.
  • This class is available when the XB_DBF7_SUPPORT option is compiled into the library.
  • The time stamp contains the number of milliseconds since 01/01/0001.
  • There is no accounting for time zone in the field.
  • A value of all zeroes is considered null.

    Class xbTimeStamp methods

    MethodDescriptionParameters
    xbTimeStamp()
    xbTimeStamp( xbInt32 lDate, xbInt32 lTime )
    xbTimeStamp( xbInt32 lDate, xbTime tm )
    xbTimeStamp( xbDate dt, xbInt32 lTime )
    xbTimeStamp( xbDate dt, xbTime tm )
    xbTimeStamp( const xbString &sTs )
    Various constructors. lDate - long integer date value - the number of days since 01/01/4713 BC.
    lTime - long integer time value - hours * 3600000L + minutes * 60000L + Seconds * 1000L.
    dt - xbDate object as input value.
    tm - xbTime oject as input value.
    sTs - String in the format of YYYY-MM-DD hh:mm:ss
    ~xbTimeStamp() Destructor.
    xbInt16 Add( char cType, xbInt32 lAmt) Add or subtract date or time amounts from the object. cType is one of:
  • Y - Year
  • M - Month
  • D - Day
  • H - Hour
  • m - Minute
  • S - Second
    lAmt is the number of units to add to the date time object. Use negative numbers to subtract.
  • void Dump()
    void Dump( xbString & sHeader )
    Dump class internals to stdout sHeader - optional header message included with time internals.
    xbInt32 GetDate() const
    xbInt32 GetDate( xbDate &dtOut ) const
    Return the date portion of the time stamp. dtOut - Output xbDate object.
    void GetFormattedTimeStamp( const xbString &sFormatSpecifiers, xbString &sFormattedOutput ) Returns a formatted time stamp. This routine calls the standard C strftime function and uses the format specifiers associated with the function to create a formatted timestamp. sFormattedOutput - Output string value

    sFormatSpecifiers - C string containing any combination of regular characters and special format specifiers. Format specifiers are replaced by the function to the corresponding values to represent the time stamp. They all begin with a percentage (%) sign.

    SpecifierReplaced byExample
    %aAbbreviated weekday nameThu
    %AFull weekday nameThursday
    %bAbbreviated month nameAug
    %BFull month name *August
    %cDate and time representation *Thu Aug 23 14:55:02 2001
    %CYear divided by 100 and truncated to integer (00-99)20
    %dDay of the month, zero-padded (01-31)23
    %DShort MM/DD/YY date, equivalent to %m/%d/%y08/23/01
    %eDay of the month, space-padded ( 1-31)23
    %FShort YYYY-MM-DD date, equivalent to %Y-%m-%d2001-08-23
    %gWeek-based year, last two digits (00-99)01
    %GWeek-based year2001
    %hAbbreviated month name * (same as %b)Aug
    %HHour in 24h format (00-23)14
    %IHour in 12h format (01-12)02
    %jDay of the year (001-366)235
    %mMonth as a decimal number (01-12)08
    %MMinute (00-59)55
    %nNew-line character
    %pAM or PM designation PM
    %r12-hour clock time * 02:55:02 pm
    %R24-hour HH:MM time, equivalent to %H:%M14:55
    %SSecond (00-61)02
    %tHorizontal-tab character
    %TISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S14:55:02
    %uISO 8601 weekday as number with Monday as 1 (1-7)4
    %UWeek number with the first Sunday as the first day of week one (00-53)33
    %VISO 8601 week number (01-53) 34
    %wWeekday as a decimal number with Sunday as 0 (0-6) 4
    %WWeek number with the first Monday as the first day of week one (00-53)34
    %xDate representation *08/23/01
    %XTime representation *14:55:02
    %yYear, last two digits (00-99)01
    %YYear2001
    %%A % sign%
    xbInt32 GetTime() const
    xbInt32 GetTime( xbTime &tmOut ) const
    Return the time portion of the time stamp. dtOut - Output xbTime object.
    void SetTmStruct( struct tm *timePtr ) Populate a C standard struct tm date and time field from the xbTimeStamp Value. timePtr - Pointer to allocated time structure.
    xbBool IsNull() const Returns xbTrue if the timestamp is null, else returns xbFalse.
    void Now() Set the time stamp to the current system date and time.
    Same as method Systime().
    void SetDate( xbInt32 lDate ) Set the date portion of the time stamp. lDate - long integer date value. The number of days since 01/01/4713 BC.
    void SetDate( xbDate &dt )
    Set the date portion of the time stamp. dt - xbDate object as input value.
    void SetNull() Initialize the time stamp to null.
    void SetTime( xbInt32 lTime )
    void SetTime( xbTime &tm )
    Set the time portion of the time stamp. tm - xbTime oject as input value.
    lTime - long integer time value = (hours * 3600000L + minutes * 60000L + Seconds * 1000L).
    void Systime() Set DateTime to the system date and time.
    Same as method Now()
    xbTimeStamp &operator = (const xbTimeStamp &dt) Set operator, returns xbTimeStamp.
    xbBool operator == (const xbTimeStamp &dt) const Equality operator.
    Returns xbTrue if xbTimeStamps match else returns xbFalse.
    dt - DateTime to compare.
    xbBool operator != (const xbTimeStamp &dt) const Inequality operator.
    Returns xbTrue if xbTimeStamps don't match else returns xbFalse.
    dt - DateTime to compare.
    xbBool operator < (const xbTimeStamp &dt) const Less than operator.
    Returns xbTrue if dt is less than else returns xbFalse.
    dt - DateTime to compare.
    xbBool operator <= (const xbTimeStamp &dt) const Less than or equal operator.
    Returns xbTrue if dt is less than or equal else returns xbFalse.
    dt - DateTime to compare.
    xbBool operator > (const xbTimeStamp &dt) const Greater than operator.
    Returns xbTrue if dt is greater than else returns xbFalse.
    dt - DateTime to compare.
    xbBool operator >= (const xbTimeStamp &dt) const Greater than or equal operator.
    Returns xbTrue if dt is greater than or equal else returns xbFalse.
    dt - DateTime to compare.





    Example program snippet using xbTimeStamp class

    xbTimeStamp ts1; if( ts1.IsNull()) std::cout << "Field ts1 is null\n"; else std::cout << "Field ts1 is not null\n"; // create an xbTimeStamp field from an xbDate and an xbTime xbDate dt1( 2, 3, 1989 ); xbTime tm1( 11, 12, 13 ); xbTimeStamp ts2( dt1, tm1 ); ts1.Dump( "Field ts1 values:" ); std::cout << "Internal Date Value: " << ts1.GetDate() << std::endl; std::cout << "Internal Time Value: " << ts1.GetDate() << std::endl; // create a new time stamp and copy it from ts1 xbTimeStamp ts3( ts1 ); // Add 5 minutes to it ts2.Add( 'm', 5 ); // Y=Year, M=Month, D=Day, H=Hour, m=Minute, S=Second if( ts1 == ts3 ) // also available: !=, <=, <, >, >= std::cout << "ts1 = ts3\n"; else std::cout << "ts1 <= ts3\n"; ts2.Dump( "New ts2 after adding 5 minutes:" ); xbTimeStamp ts4; ts4.Systime(); ts4.Dump( "System Time Stamp:" ); xbTimeStamp ts5; ts5 = ts3; // Set ts4 = ts3