timestamp – Tools for representing MongoDB internal Timestamps — PyMongo 2.5 documentation

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »
- `bson` – BSON (Binary JSON) Encoding and Decoding »

# `timestamp` – Tools for representing MongoDB internal Timestamps

New in version 1.5.

Tools for representing MongoDB internal Timestamps.

class `bson.timestamp.``Timestamp`(time, inc)

  Create a new `Timestamp`.

  This class is only for use with the MongoDB opLog. If you need to store a regular timestamp, please use a `datetime`.

  Raises `TypeError` if time is not an instance of :class: int or `datetime`, or inc is not an instance of `int`. Raises `ValueError` if time or inc is not in [0, 2**32).

  Parameters : | time: time in seconds since epoch UTC, or a naive UTC `datetime`, or an aware `datetime` inc: the incrementing counter

  Changed in version 1.7: time can now be a `datetime` instance.

  `as_datetime`()

    Return a `datetime` instance corresponding to the time portion of this `Timestamp`.

    Changed in version 1.8: The returned datetime is now timezone aware.

  `inc`

    Get the inc portion of this `Timestamp`.

  `time`

    Get the time portion of this `Timestamp`.

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »
- `bson` – BSON (Binary JSON) Encoding and Decoding »