dates#
relationalai.std
RAI date and datetime values are represented by Expression
objects. The relationalai.std.dates
module is an anlog of the Python datetime
module for working with RAI dates and datetimes.
NOTE
The actual values of properties and other data in a RAI model are only determined during query evaluation in the RAI Native App.
As a result, the Python interpreter can’t access the types or values of data in the model, which means string data can’t be represented as Python str
objects.
To import the dates
module, add the following to the top of your Python file or notebook:
#from relationalai.std import dates
Table of Contents#
- Date Constructors
- Datetime Constructors
- Date Ranges
- Date and Datetime Filters
- String Formatting
- Date and Time Parts
- Date Arithmetic and Time Periods
Date Constructors#
Constructor | Description | Return Type |
---|---|---|
date() | Constructs date values from year, month, and day values. | Expression |
date.fromisoformat() | Constructs date values from ISO-formatted strings (YYYY-MM-DD ). | Expression |
date.fromdatetime() | Constructs date values from datetime values. | Expression |
date.fromordinal() | Constructs date values from ordinal numbers. | Expression |
Datetime Constructors#
Constructor | Description | Return Type |
---|---|---|
datetime() | Constructs UTC datetime values from year, month, day, hour, minute, second, and millisecond values. | Expression |
datetime.fromdate() | Constructs UTC datetime values from date values. | Expression |
datetime.fromordinal() | Constructs UTC datetime values from ordinal numbers. | Expression |
datetime.strptime() | Constructs UTC datetime values from formatted strings. Common ISO formats can be accessed by name using the ISO namespace. | Expression |
Date Ranges#
Function | Description | Return Type |
---|---|---|
date_range() | Creates a range of date values. | Expression |
Date and Datetime Filters#
Function | Description | Return Type |
---|---|---|
Date() | Filter date values from a Producer . | Expression |
DateTime() | Filter datetime values from a Producer . | Expression |
String Formatting#
Function/Class | Description | Return Type |
---|---|---|
strftime() | Formats a date or datetime according to a format string. | Expression |
ISO | A namespace with common ISO date and datetime formats. |
Date and Time Parts#
Function | Description | Return Type |
---|---|---|
year() | Extracts the year from a date or datetime value. | Expression |
month() | Extracts the month from a date or datetime value. | Expression |
day() | Extracts the day from a date or datetime value. | Expression |
hour() | Extracts the hour from a datetime value. | Expression |
minute() | Extracts the minute from a datetime value. | Expression |
second() | Extracts the second from a datetime value. | Expression |
quarter() | Computes the quarter (1-4) from a date or datetime value. | Expression |
week() | Computes the ISO week number (1-53) from a date or datetime value. | Expression |
dayofyear() | Computes the day of the year from a date or datetime value as an integer between 1 and 365 (or 366 in a leap year). | Expression |
weekday() | Computes the day of the week (0-6) from a date or datetime value as an integer where Monday is 0 and Sunday is 6 . | Expression |
isoweekday() | Computes the ISO day of the week (1-7) from a date or datetime value as an integer where Monday is 1 and Sunday is 7. | Expression |
Date Arithmetic and Time Periods#
Function | Description | Return Type |
---|---|---|
date_add() | Adds a time period to a date or datetime value. | Expression |
date_subtract() | Subtracts a time period from a date or datetime value. | Expression |
years() | Creates a time period in years. | Expression |
months() | Creates a time period in months. | Expression |
days() | Creates a time period in days. | Expression |
hours() | Creates a time period in hours. | Expression |
minutes() | Creates a time period in minutes. | Expression |
seconds() | Creates a time period in seconds. | Expression |
milliseconds() | Creates a time period in milliseconds. | Expression |
microseconds() | Creates a time period in microseconds. | Expression |
nanoseconds() | Creates a time period in nanoseconds. | Expression |