Date conditions
All date conditions can be used either with datetime.datetime or with datetime.date. All examples on this page are using datetime, but can be replaced by date.
before(date): Check if date is before another date
before(date): Check if date is before another dateCheck if a datetime/date is before a given datetime/date.
Stream.of([datetime.now() - timedelta(days=1)])\
.filter(before(datetime.now()))\
.for_each(print) # Output: 2023-06-01 17:03:54.386812after(date): Check if date is after another date
after(date): Check if date is after another dateCheck if a datetime/date is after a given datetime/date.
Stream.of([datetime.now() + timedelta(days=1)])\
.filter(after(datetime.now()))\
.for_each(print) # Output: 2023-06-03 17:03:54.386812before_or_equal(date): Check if date is before or equal to another date
before_or_equal(date): Check if date is before or equal to another dateCheck if a datetime/date is before or equal to a given datetime/date.
Stream.of([datetime.now() - timedelta(days=1)])\
.filter(before_or_equal(datetime.now()))\
.for_each(print) # Output: 2023-06-01 17:03:54.386812after_or_equal(date): Check if date is after or equal to another date
after_or_equal(date): Check if date is after or equal to another dateCheck if a datetime/date is after or equal to a given datetime/date.
Stream.of([datetime.now() + timedelta(days=1)])\
.filter(after_or_equal(datetime.now()))\
.for_each(print) # Output: 2023-06-03 17:03:54.386812between_or_equal(start_date, end_date): Check if date is between or equal to two dates
between_or_equal(start_date, end_date): Check if date is between or equal to two datesCheck if a datetime/date is between or equal to two given datetimes/date.
Stream.of([datetime.now() - timedelta(days=2)])\
.filter(between_or_equal(datetime.now() - timedelta(days=3), datetime.now() - timedelta(days=1)))\
.for_each(print) # Output: 2023-06-01 17:03:54.386812not_between_or_equal(start_date, end_date): Check if date is not between or equal to two dates
not_between_or_equal(start_date, end_date): Check if date is not between or equal to two datesCheck if a datetime/date is not between or equal to two given datetimes/dates.
Stream.of([datetime.now() - timedelta(days=2)])\
.filter(not_between_or_equal(datetime.now() - timedelta(days=3), datetime.now() - timedelta(days=1)))\
.for_each(print) # Output: (no output)today(): Check if date is today
today(): Check if date is todayCheck if a datetime/date is today.
Stream.of([datetime.now()])\
.filter(today())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812today_utc(): Check if date is today in UTC
today_utc(): Check if date is today in UTCCheck if a datetime/date is today (in UTC).
Stream.of([datetime.now(timezone.utc)])\
.filter(today_utc())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812yesterday(): Check if date is yesterday
yesterday(): Check if date is yesterdayCheck if a datetime/date is yesterday.
Stream.of([datetime.now() - timedelta(days=1)])\
.filter(yesterday())\
.for_each(print) # Output: 2023-06-01 17:03:54.386812yesterday_utc(): Check if date is yesterday in UTC
yesterday_utc(): Check if date is yesterday in UTCCheck if a datetime/date is yesterday (in UTC).
Stream.of([datetime.now(timezone.utc) - timedelta(days=1)])\
.filter(yesterday_utc())\
.for_each(print) # Output: 2023-06-01 17:03:54.386812tomorrow(): Check if date is tomorrow
tomorrow(): Check if date is tomorrowCheck if a datetime/date is tomorrow.
Stream.of([datetime.now() + timedelta(days=1)])\
.filter(tomorrow())\
.for_each(print) # Output: 2023-06-03 17:03:54.386812tomorrow_utc(): Check if date is tomorrow in UTC
tomorrow_utc(): Check if date is tomorrow in UTCCheck if a datetime/date is tomorrow (in UTC).
Stream.of([datetime.now(timezone.utc) + timedelta(days=1)])\
.filter(tomorrow_utc())\
.for_each(print) # Output: 2023-06-03 17:03:54.386812this_week(): Check if date is within the current week
this_week(): Check if date is within the current weekCheck if a datetime/date is within the current week.
Stream.of([datetime.now()])\
.filter(this_week())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812this_week_utc(): Check if date is within the current week in UTC
this_week_utc(): Check if date is within the current week in UTCCheck if a datetime/date is within the current week (in UTC).
Stream.of([datetime.now(timezone.utc)])\
.filter(this_week_utc())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812last_week(): Check if date is within the previous week
last_week(): Check if date is within the previous weekCheck if a datetime/date is within the previous week.
Stream.of([datetime.now() - timedelta(weeks=1)])\
.filter(last_week())\
.for_each(print) # Output: 2023-05-26 17:03:54.386812last_week_utc(): Check if date is within the previous week in UTC
last_week_utc(): Check if date is within the previous week in UTCCheck if a datetime/date is within the previous week (in UTC).
Stream.of([datetime.now(timezone.utc) - timedelta(weeks=1)])\
.filter(last_week_utc())\
.for_each(print) # Output: 2023-05-26 17:03:54.386812next_week(): Check if date is within the next week
next_week(): Check if date is within the next weekCheck if a datetime/date is within the next week.
Stream.of([datetime.now() + timedelta(weeks=1)])\
.filter(next_week())\
.for_each(print) # Output: 2023-06-09 17:03:54.386812next_week_utc(): Check if date is within the next week in UTC
next_week_utc(): Check if date is within the next week in UTCCheck if a datetime/date is within the next week (in UTC).
Stream.of([datetime.now(timezone.utc) + timedelta(weeks=1)])\
.filter(next_week_utc())\
.for_each(print) # Output: 2023-06-09 17:03:54.386812this_month(): Check if date is within the current month
this_month(): Check if date is within the current monthCheck if a datetime/date is within the current month.
Stream.of([datetime.now()])\
.filter(this_month())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812this_month_utc(): Check if date is within the current month in UTC
this_month_utc(): Check if date is within the current month in UTCCheck if a datetime/date is within the current month (in UTC).
Stream.of([datetime.now(timezone.utc)])\
.filter(this_month_utc())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812last_month(): Check if date is within the previous month
last_month(): Check if date is within the previous monthCheck if a datetime/date is within the previous month.
Stream.of([datetime.now() - relativedelta(months=1)])\
.filter(last_month())\
.for_each(print) # Output: 2023-05-02 17:03:54.386812last_month_utc(): Check if date is within the previous month in UTC
last_month_utc(): Check if date is within the previous month in UTCCheck if a datetime/date is within the previous month (in UTC).
Stream.of([datetime.now(timezone.utc) - relativedelta(months=1)])\
.filter(last_month_utc())\
.for_each(print) # Output: 2023-05-02 17:03:54.386812next_month(): Check if date is within the next month
next_month(): Check if date is within the next monthCheck if a datetime/date is within the next month.
Stream.of([datetime.now() + relativedelta(months=1)])\
.filter(next_month())\
.for_each(print) # Output: 2023-07-02 17:03:54.386812next_month_utc(): Check if date is within the next month in UTC
next_month_utc(): Check if date is within the next month in UTCCheck if a datetime/date is within the next month (in UTC).
Stream.of([datetime.now(timezone.utc) + relativedelta(months=1)])\
.filter(next_month_utc())\
.for_each(print) # Output: 2023-07-02 17:03:54.386812this_year(): Check if date is within the current year
this_year(): Check if date is within the current yearCheck if a datetime/date is within the current year.
Stream.of([datetime.now()])\
.filter(this_year())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812this_year_utc(): Check if date is within the current year in UTC
this_year_utc(): Check if date is within the current year in UTCCheck if a datetime/date is within the current year (in UTC).
Stream.of([datetime.now(timezone.utc)])\
.filter(this_year_utc())\
.for_each(print) # Output: 2023-06-02 17:03:54.386812last_year(): Check if date is within the previous year
last_year(): Check if date is within the previous yearCheck if a datetime/date is within the previous year.
Stream.of([datetime.now() - relativedelta(years=1)])\
.filter(last_year())\
.for_each(print) # Output: 2022-06-02 17:03:54.386812last_year_utc(): Check if date is within the previous year in UTC
last_year_utc(): Check if date is within the previous year in UTCCheck if a datetime/date is within the previous year (in UTC).
Stream.of([datetime.now(timezone.utc) - relativedelta(years=1)])\
.filter(last_year_utc())\
.for_each(print) # Output: 2022-06-02 17:03:54.386812next_year(): Check if date is within the next year
next_year(): Check if date is within the next yearCheck if a datetime/date is within the next year.
Stream.of([datetime.now() + relativedelta(years=1)])\
.filter(next_year())\
.for_each(print) # Output: 2024-06-02 17:03:54.386812next_year_utc(): Check if date is within the next year in UTC
next_year_utc(): Check if date is within the next year in UTCCheck if a datetime/date is within the next year (in UTC).
Stream.of([datetime.now(timezone.utc) + relativedelta(years=1)])\
.filter(next_year_utc())\
.for_each(print) # Output: 2024-06-02 17:03:54.386812Last updated
Was this helpful?