days()#

relationalai.std.dates
#days(n: int | Producer) -> Expression

Produces a period of n days. Must be called in a rule or query context.

Parameters#

NameTypeDescription
nint or ProducerThe number of days.

Returns#

An Expression that represents a period of n days.

Example#

Use days() to create a period of n days. 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 date, days

# Create a model named "events" with an `Event` type.
model = rai.Model("events")
Event = model.Type("Event")

# Add an event with a start date.
with model.rule():
    Event.add(name="Conference", start_date=date(2021, 1, 1))

# Add 7 days to the event start date.
with model.query() as select:
    event = Event(name="Conference")
    new_date = event.start_date + days(7)
    response = select(event.name, alias(new_date, "new_date"))

print(response.results)
# Output:
#          name   new_date
# 0  Conference 2021-01-08

See date_add() and date_subtract() for more details on manipulating Date and DateTime values.

See Also#