Thanks to visit codestin.com
Credit goes to github.com

Skip to content

st.date_input() date range quick select input inconsistent max_value validation #12293

@alexmalins

Description

@alexmalins

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

#10166 added a date range quick select drop down to st.date_input() which uses BaseWeb's stateful quick select datepicker. That component returns JavaScript Date instances anchored at 12:00:00 (midday).

This means the st.date_input() date validation introduced in #10764 incorrectly warns the date ranges inputted by the quick select drop down (Past Week, Past Month...) has an invalid upper date when st.date_input() is called with max_value=datetime.now().date(), because today 12:00 (BaseWeb Date) > today 00:00 (Streamlit max_date).

Reproducible Code Example

import datetime
import streamlit as st

today = datetime.datetime.now().date()
min_date = today - datetime.timedelta(days=800)
min_date, today

d = st.date_input(
    "Input date range",
    value=(min_date, today),
    min_value=min_date,
    max_value=today,
    format="MM.DD.YYYY",
)
d

Steps To Reproduce

Screencast_20250822_230006.webm

Expected Behavior

A way to fix this would be to change the Date objects returned by BaseWeb quick select by stripping the 12:00 time component to just 00:00.

I.e. put operations like this: dateObject.setHours(0, 0, 0, 0); into https://github.com/streamlit/streamlit/blob/develop/frontend/lib/src/components/widgets/DateInput/DateInput.tsx

This would mean the validation introduced by #10764 would always be making 00:00 Date comparisons, and the quick select date ranges would pass validation correctly when st.date_input(..., max_value=datetime.now().date(), ...).

Current Behavior

See vid

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.48.1
  • Python version: 3.13
  • Operating System: Linux
  • Browser: Chrome

Additional Information

No response

Metadata

Metadata

Assignees

Labels

feature:st.date_inputRelated to the `st.date_input` widgetpriority:P3Medium prioritystatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions