cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Job parameters to get date and time

mh_db
New Contributor III

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  yearmonthdayhourminutesecond 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?

5 REPLIES 5

brockb
Databricks Employee
Databricks Employee

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
```

 
Hope this helps.

mh_db
New Contributor III

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)

brockb
Databricks Employee
Databricks Employee

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`?

mh_db
New Contributor III

I have LoadID as key and value {{job.start_time.[iso_datetime]}}

brockb
Databricks Employee
Databricks Employee

Then please change the code to:
```
iso_datetime = dbutils.widgets.get("LoadID")
```

Connect with Databricks Users in Your Area

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