04-30-2024 11:22 AM
I'm trying to set up a workflow in databricks and I need my job parameter to get the date and time. I see in the documentation there's some options for dynamic values.
I'm trying to use this one: {{job.start_time.[argument]}}
For the "argument" there, is it possible to have multiple arguments? if so, what's the right sintax? I'm trying to used year, month, day, hour, minute, second as I see in the documentation these are valid arguments, but seems it's only taking one at a time. How do I get all?
05-01-2024 08:16 AM
Hi,
You have different options, one could be to setup the job with multiple parameters. So one parameter called `year` is represented by `{{job.start_time.[year]}}`, another `month` represented by `{{job.start_time.[month]}}`, etc.
Alternatively, you could pass a single argument like `{{job.start_time.[iso_datetime]}}` and then parse each of the values of interest in your program. For example:
```
import datetime
iso_datetime: str = dbutils.widgets.get("iso_datetime")
date_object = datetime.datetime.strptime(iso_datetime, "%Y-%m-%dT%H:%M:%S.%f")
print(date_object.year, date_object.month, date_object.day)
2024 5 1
```
05-02-2024 12:57 PM
I defined the job parameter in job using {{job.start_time.[iso_datetime]}} and then I added the lines you suggested in notebook but getting an error "com.databricks.dbutils_v1.InputWidgetNotDefined: No input widget named iso_datetime is defined"
import datetime
iso_datetime: str = dbutils.widgets.get("iso_datetime")
date_object = datetime.datetime.strptime(iso_datetime, "%Y-%m-%dT%H:%M:%S.%f")
print(date_object.year, date_object.month, date_object.day)
05-02-2024 01:45 PM
When adding parameters to the job under "Edit Parameters", you provide a `Key` and then the `Value`. In my example, the `Key` was `iso_datetime` (which is what was referenced in the notebook) and the `Value` was `{{job.start_time.[iso_datetime]}}`.
What was the name of your `Key`?
05-02-2024 01:47 PM
I have LoadID as key and value {{job.start_time.[iso_datetime]}}
05-02-2024 04:12 PM
Then please change the code to:
```
iso_datetime = dbutils.widgets.get("LoadID")
```
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group