🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators allInstancesAtTime
This page was created by Alexandra on 2017-08-13. Last edited by Wikiadmin on 2026-07-29.

You can use allInstancesAtTime in OCL to retrieve the instances of a versioned class as they existed at one point on MDriven's integer timestamp timeline; use it for historical reporting, auditing, and comparisons with the current object set.

What allInstancesAtTime returns

allInstancesAtTime returns the historical state of all instances of a class at the supplied timestamp.

For example, if Complaint is versioned, this expression retrieves the complaints as they existed at the timestamp that represents 1 January 2025 at midnight:

Complaint.allInstancesAtTime(DateTime.Parse('2025-01-01 00:00:00').timeToTimeStamp)

Use allInstances when you need the existing instances in the current state. Use allInstancesAtTime when the point in time is part of the question.

Prerequisite: version the class

The target class must have its Versioned property set to True. Versioning records object versions by using inserts rather than SQL update or delete operations, with TimeStampStart and TimeStampStop stored as non-attribute database columns. This history enables temporal operators such as allInstancesAtTime.

To prepare a class for historical queries:

  1. Select the class in MDriven Designer.
  2. Set the class's Versioned property to True.
  3. Update the database schema so that the versioned storage is available.
  4. Query the class with allInstancesAtTime using an integer timestamp.

For the storage behavior and other versioning operators, see Documentation:Versioned on class.

Syntax

ClassName.allInstancesAtTime(timeStamp : Integer)
Part Meaning
ClassName The versioned class to query, for example Complaint.
timeStamp An integer timestamp, not a DateTime value.

Convert a calendar time to a timestamp

The operator requires an Integer. Convert a DateTime expression with timeToTimeStamp before passing it to allInstancesAtTime.

Query a fixed date and time

Parse the date and time, then convert the result:

Complaint.allInstancesAtTime(DateTime.Parse('2025-01-01 00:00:00').timeToTimeStamp)

Query a time relative to now

For example, retrieve the historical complaint set from 30 days ago:

Complaint.allInstancesAtTime(DateTime.Now.AddDays(-30).timeToTimeStamp)

The reverse conversion is timeStampToTime. For example, Documentation:Versioned on class shows how to read an object's integer timestamp with objectTimeStamp, convert it to a calendar DateTime, and convert it back again.

Common errors

Error or symptom Cause Resolution
System.DateTime does not conform to System.Int32 A DateTime was supplied directly where the operator requires an integer timestamp. Convert the value before calling the operator. For example: DateTime.Now.AddDays(-30).timeToTimeStamp.
Specified method is not supported. ,InternalEvaluate()... The class does not have history tracking available for the temporal query. Set the class's Versioned property to True, update the database schema, and then run the query against the versioned class.

Working with historical results

allInstancesAtTime gives you the set of objects at the requested point in time. If you need to investigate the timestamp associated with an object version, use objectTimeStamp. If you need the current set instead of a historical set, use allInstances.

To discover other available OCL operations, open the OCL Editor and type a class name. See Documentation:OCL General Operators.

See also