milliseconds()#
relationalai.std.dates
#milliseconds(n: int | Producer) -> Expression
Produces a period of n
milliseconds.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
n | int or Producer | The number of milliseconds. |
Returns#
An Expression
that represents a period of n
milliseconds.
Example#
Use milliseconds()
to create a period of n
milliseconds.
You can add and subtract time periods from Date
or DateTime
values using the +
and -
operators:
#import relationalai as rai
from relationalai.std import alias
from relationalai.std.dates import datetime, milliseconds
# Create a model named "events" with an `Event` type.
model = rai.Model("events")
Event = model.Type("Event")
# Add an event with a start datetime.
with model.rule():
Event.add(
name="Conference",
starts_at=datetime(2021, 1, 1, 9, 0, 0, tz="UTC")
)
# Add 500 milliseconds to the event start datetime.
with model.query() as select:
event = Event(name="Conference")
new_datetime = event.starts_at + milliseconds(500)
response = select(event.name, alias(new_datetime, "new_time"))
print(response.results)
# Output:
# name new_time
# 0 Conference 2021-01-01 09:00:00.500
You can’t add or subtract milliseconds()
from a Date
.
See date_add()
and
date_subtract()
for details.