The Get Formatted Date Data Block (fn_GetFormattedDate) Data Block in Assette is a Python-based Transform block that converts an input date into a user-specified output format. This block is useful when you need to transform dates into a particular string format for display in reports, client communications, or more commonly, as a dependency in another Data Block
General Info #
| Field | Value |
|---|---|
| Name | fn_GetFormattedDate |
| Block Category | Transform |
| Block Type | Python |
| Output Type | Values |
| Editable | True |
Definition #
"""
params:{
"InputDate": AsOfDate,
"OutputFormat": Date_Format
}
test param values:{
"InputDate":"2023-12-31",
"OutputFormat":"%B-%d-%y"
}
response = "A converted date in required format"
"""
InputDate = params["InputDate"]
OutputFormat = params["OutputFormat"]
def convert_date(InputDate, OutputFormat):
try:
# Try to use InputDate as a datetime object with timestamp
date_obj = datetime.datetime.strptime(str(InputDate), '%Y-%m-%dT%H:%M:%S').date()
except:
try:
# Try to use InputDate as a date object without timestamp
date_obj = datetime.datetime.strptime(str(InputDate), '%Y-%m-%d').date()
except ValueError as e:
return f"Error during date conversion: {str(e)}"
# Format the date object according to the specified output format
formatted_date = date_obj.strftime(OutputFormat)
return formatted_date
result = convert_date(InputDate, OutputFormat)
response["values"] = result
Columns #
None. This block returns a single formatted value based on the provided input parameters.
Request Parameters #
| Parameter | Display Name | Data Type | Required | Description |
|---|---|---|---|---|
| InputDate | Input Date | Date | Yes | The date value to be converted. Supports both plain date (YYYY-MM-DD) and ISO datetime with timestamp (YYYY-MM-DDTHH:MM:SS). |
| OutputFormat | Output Format | Text | Yes | A valid Python date format string (e.g., %B-%d-%y, %m/%d/%Y, %Y-%m-%d). Determines how the output date is displayed. |
Dependencies #
| Dependent Block | Description |
|---|---|
| PythonEnvForDateCalculation | Defines the imported Python modules and libraries (e.g., “numpy as np”) [Link] |
Examples #
The following examples demonstrate how the fn_GetFormattedDate Data Block successfully converts dates into different output formats. Each example uses a valid input date and a valid Python strftime format string.
Example 1: Full Month Name, Day, and Two-Digit Year #
Request
{
"InputDate": "2023-12-31",
"OutputFormat": "%B-%d-%y"
}
Response
%B→ Full month name (December)%d→ Day of the month (31)%y→ Two-digit year (23)
Result: "December-31-23"
{
"values": "December-31-23",
"errors": [],
"success": true,
"logs": [],
"sources": []
}
Example 2: Month/Day/Four-Digit Year #
Request
{
"InputDate": "2023-12-31T15:45:00",
"OutputFormat": "%m/%d/%Y"
}
Response
%m→ Month number (12)%d→ Day (31)%Y→ Four-digit year (2023)
Result: "12/31/2023"
{
"values": "12/31/2023",
"errors": [],
"success": true,
"logs": [],
"sources": []
}
Example 3: Year-Month-Day (Standard ISO Output) #
Request
{
"InputDate": "2023-12-31",
"OutputFormat": "%Y-%m-%d"
}
Response
This matches the common ISO date format used in many systems.
{
"values": "2023-12-31",
"errors": [],
"success": true,
"logs": [],
"sources": []
}
Example 4: Day-Month Abbreviation-Year #
Request
{
"InputDate": "2023-12-31",
"OutputFormat": "%d-%b-%Y"
}
Response
%d→ Day (31)%b→ Abbreviated month name (Dec)%Y→ Four-digit year (2023)
Result: "31-Dec-2023"
{
"values": "31-Dec-2023",
"errors": [],
"success": true,
"logs": [],
"sources": []
}
Example 5: Weekday, Full Month Name, and Year #
Request
{
"InputDate": "2023-12-31",
"OutputFormat": "%A, %B %d, %Y"
}
Response
%A→ Full weekday name (Sunday)%B→ Full month name (December)%d→ Day (31)%Y→ Year (2023)
Result: "Sunday, December 31, 2023"
{
"values": "Sunday, December 31, 2023",
"errors": [],
"success": true,
"logs": [],
"sources": []
}
Example 6: Year and Week Number #
Request
{
"InputDate": "2023-12-31",
"OutputFormat": "%Y-W%U"
}
Response
%Y→ Year (2023)%U→ Week number of the year (Sunday as first day of the week)
Result: "2023-W52"
{
"values": "2023-W53",
"errors": [],
"success": true,
"logs": [],
"sources": []
}