ISO#

relationalai.std.dates
#class ISO

Namespace class containing common ISO format strings for dates and times. Use these format strings with datetime.strptime() and strftime() to parse date strings and format dates.

Attributes#

NameValue
.DATE"y-m-d"
.HOURS"y-m-dTH:M:S"
.HOURS_TZ"y-m-dTHz"
.MINUTES"y-m-dTH:M"
.MINUTES_TZ"y-m-dTH:Mz"
.SECONDS"y-m-dTH:M:S"
.SECONDS_TZ"y-m-dTH:M:Sz"
.MILLIS"y-m-dTH:M:S.s"
.MILLIS_TZ"y-m-dTH:M:S.sz"

See Format Codes for details on the format codes used in RAI format strings.

Example#

You do not need to instantiate the ISO class to use its attributes. Access attributes directly from the class and pass them to datetime.strptime() or strftime() to parse or format date strings:

#import relationalai as rai
from relationalai.std.dates import datetime, ISO, strftime


# =====
# SETUP
# =====

model = rai.Model("MyModel")
Person = model.Type("Person")

with model.rule():
    Person.add(id=1).set(name="Alice", birthdate_str="2001-01-01T13:00:00")


# =======
# EXAMPLE
# =======

with model.rule():
    person = Person()
    # Set the birthdate property to the datetime value parsed from the birthdate_str property.
    person.set(birthdate=datetime.strptime(person.birthdate_str, ISO.SECONDS))

with model.query() as select:
    person = Person()
    # Format the person.birthdate property as an ISO date string (YYYY-MM-DD).
    formatted_birthdate = strftime(person.birthdate, ISO.DATE)
    response = select(person.name, person.birthdate, formatted_birthdate)

print(response.results)
#     name           birthdate           v
# 0  Alice 2001-01-01 13:00:00  2001-01-01

See Also#