ISO#
relationalai.std.dates
#class ISO
Contains attributes with common ISO format strings for dates and datetimes.
Use these format strings with datetime.strptime()
and strftime()
to parse date strings and format dates.
Attributes#
Name | Value |
---|---|
ISO.DATE | "y-m-d" |
ISO.HOURS | "y-m-dTH:M:S" |
ISO.HOURS_TZ | "y-m-dTHz" |
ISO.MINUTES | "y-m-dTH:M" |
ISO.MINUTES_TZ | "y-m-dTH:Mz" |
ISO.SECONDS | "y-m-dTH:M:S" |
ISO.SECONDS_TZ | "y-m-dTH:M:Sz" |
ISO.MILLIS | "y-m-dTH:M:S.s" |
ISO.MILLIS_TZ | "y-m-dTH:M:S.sz" |
See Format Codes for more details on the format codes used in RAI format strings.
Example#
Use the ISO
namespace to parse an ISO-formatted date string using datetime.strptime()
or format a datetime value as an ISO-formatted string using strftime()
:
#import relationalai as rai
from relationalai.std import dates
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Event = model.Type("Event")
with model.rule():
Event.add(id=1).set(time_str="2021-01-01T12:00:00")
# =======
# EXAMPLE
# =======
with model.rule():
event = Event()
event.set(
# Parse event.time_str as a datetime value.
time=dates.datetime.strptime(event.time_str, dates.ISO.SECONDS,
# Format time as an ISO-formatted date.
date_str=dates.strftime(time, dates.ISO.DATE)
)
with model.query() as select:
event = Event()
response = select(event.id, event.time, event.date_str)
print(response.results)
# id time date_str
# 0 1 2021-01-01 12:00:00 2021-01-01