Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 09:05 AM - edited 07-28-2025 09:06 AM
Hi @zc ,
Exactly, this is what I meant. What is funny though, that in python cell you can define variable and then later use it as a widget's default value. So there's a bit of inconsistency here between different types of cells.
Following works in python cell:
from datetime import datetime
from dateutil.relativedelta import relativedelta
date1_str = "2025-01-31"
date2_str = None
date1_obj = datetime.strptime(date1_str, "%Y-%m-%d").date()
date2_obj = date1_obj + relativedelta(months=5)
date2_str = date2_obj.strftime("%Y-%m-%d")
print(f"date1: {date1_str}") # 2025-01-31
print(f"date2: {date2_str}") # 2025-06-30
dbutils.widgets.text("date1", date1_str)
dbutils.widgets.text("date2", date2_str)