months()#

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

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

Parameters#

NameTypeDescription
nint or ProducerThe number of months.

Returns#

An Expression that represents a period of n months.

Example#

Use months() to create a period of n months. You can add and subtract time periods from Date or DateTime values using the + and - operators:

#import relationalai as rai
from relationalai.std.dates import date, months

# 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 6 months to the event start date.
with model.query() as select:
    event = Event(name="Conference")
    new_date = event.start_date + months(6)
    response = select(event.name, new_date)

print(response.results)
# Output:
#          name           v
# 0  Conference  2021-07-01

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

See Also#