minute()#

relationalai.std.dates
#minute(date: datetime | Producer, tz: str = "UTC") -> Expression

Extracts the minute component from a DateTime value. If date is a Python datetime object, the tz parameter is ignored. Must be called in a rule or query context.

Parameters#

NameTypeDescription
datedatetime or ProducerThe DateTime value from which to extract the minute.
tzstrOptional timezone component for DateTime values (default is “UTC”). Ignored if date is a Python datetime object.

Returns#

An Expression that produces the minute component of the given DateTime value.

Raises#

TypeError if the date parameter is not a datetime or Producer object.

Example#

Use minute() to extract the minute component from a DateTime value:

#import relationalai as rai
from relationalai.std import alias
from relationalai.std.dates import minute, datetime

# Create a model named "people" with a `Person` type.
model = rai.Model("people")
Person = model.Type("Person")

# Add a person with a birth datetime.
with model.rule():
    Person.add(
        name="Bob",
        born_at=datetime(1985, 8, 15, 15, 45, 0, tz="UTC")
    )

# Extract the minute from `born_at`.
with model.query() as select:
    person = Person()
    birth_minute = minute(person.born_at)
    response = select(person.name, alias(birth_minute, "birth_minute"))

print(response.results)
# Output:
#   name  birth_minute
# 0  Bob            45

See Also#