I have 2 datepickers (one for start date and one for end date). I would like to be able to get a list of all years between what the user selects.
So for example, if the user chooses 2022 as a start year and 2030 as an end year, I would like to return a list of all years from 2022 until 2030. So in this case, I want html.H1 to return the list. Can you please advise?
Code below:
dcc.DatePickerSingle(id="lease_start_date",
initial_visible_month=date.today(),
placeholder="MM/DD/YYYY",
style={"margin-left": "20px", "font-size": 13}),
dcc.DatePickerSingle(id="lease_end_date",
initial_visible_month=date.today(),
placeholder="MM/DD/YYYY",
style={"margin-left": "20px", "font-size": 13}),
html.H1(id="test")
@app.callback(
Output("test", "children"),
[Input("lease_start_date", "value"),
Input("lease_end_date", "value")]
)
def get_years(year1, year2):
return [y for y in range(year1.year, year2.year + 1)]
2 posts - 2 participants









