pystreamapi
GitHub
  • Welcome to PyStreamAPI!
  • Quick Start
  • Reference
    • API Reference
      • Intermediate Operations
      • Terminal Operations
      • Numeric Stream
      • Error handling
    • Conditions
      • Type Conditions
      • Numeric Conditions
      • String Conditions
      • Date conditions
    • Data Loaders
  • Examples
  • Performance
  • Contribute
Powered by GitBook
On this page
  • before(date): Check if date is before another date
  • after(date): Check if date is after another date
  • before_or_equal(date): Check if date is before or equal to another date
  • after_or_equal(date): Check if date is after or equal to another date
  • between_or_equal(start_date, end_date): Check if date is between or equal to two dates
  • not_between_or_equal(start_date, end_date): Check if date is not between or equal to two dates
  • today(): Check if date is today
  • today_utc(): Check if date is today in UTC
  • yesterday(): Check if date is yesterday
  • yesterday_utc(): Check if date is yesterday in UTC
  • tomorrow(): Check if date is tomorrow
  • tomorrow_utc(): Check if date is tomorrow in UTC
  • this_week(): Check if date is within the current week
  • this_week_utc(): Check if date is within the current week in UTC
  • last_week(): Check if date is within the previous week
  • last_week_utc(): Check if date is within the previous week in UTC
  • next_week(): Check if date is within the next week
  • next_week_utc(): Check if date is within the next week in UTC
  • this_month(): Check if date is within the current month
  • this_month_utc(): Check if date is within the current month in UTC
  • last_month(): Check if date is within the previous month
  • last_month_utc(): Check if date is within the previous month in UTC
  • next_month(): Check if date is within the next month
  • next_month_utc(): Check if date is within the next month in UTC
  • this_year(): Check if date is within the current year
  • this_year_utc(): Check if date is within the current year in UTC
  • last_year(): Check if date is within the previous year
  • last_year_utc(): Check if date is within the previous year in UTC
  • next_year(): Check if date is within the next year
  • next_year_utc(): Check if date is within the next year in UTC

Was this helpful?

Edit on GitHub
  1. Reference
  2. Conditions

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

Check 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.386812

after(date): Check if date is after another date

Check 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.386812

before_or_equal(date): Check if date is before or equal to another date

Check 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.386812

after_or_equal(date): Check if date is after or equal to another date

Check 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.386812

between_or_equal(start_date, end_date): Check if date is between or equal to two dates

Check 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.386812

not_between_or_equal(start_date, end_date): Check if date is not between or equal to two dates

Check 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

Check if a datetime/date is today.

Stream.of([datetime.now()])\
    .filter(today())\
    .for_each(print)  # Output: 2023-06-02 17:03:54.386812

today_utc(): Check if date is today in UTC

Check 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.386812

yesterday(): Check if date is yesterday

Check 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.386812

yesterday_utc(): Check if date is yesterday in UTC

Check 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.386812

tomorrow(): Check if date is tomorrow

Check 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.386812

tomorrow_utc(): Check if date is tomorrow in UTC

Check 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.386812

this_week(): Check if date is within the current week

Check 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.386812

this_week_utc(): Check if date is within the current week in UTC

Check 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.386812

last_week(): Check if date is within the previous week

Check 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.386812

last_week_utc(): Check if date is within the previous week in UTC

Check 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.386812

next_week(): Check if date is within the next week

Check 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.386812

next_week_utc(): Check if date is within the next week in UTC

Check 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.386812

this_month(): Check if date is within the current month

Check 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.386812

this_month_utc(): Check if date is within the current month in UTC

Check 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.386812

last_month(): Check if date is within the previous month

Check 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.386812

last_month_utc(): Check if date is within the previous month in UTC

Check 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.386812

next_month(): Check if date is within the next month

Check 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.386812

next_month_utc(): Check if date is within the next month in UTC

Check 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.386812

this_year(): Check if date is within the current year

Check 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.386812

this_year_utc(): Check if date is within the current year in UTC

Check 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.386812

last_year(): Check if date is within the previous year

Check 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.386812

last_year_utc(): Check if date is within the previous year in UTC

Check 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.386812

next_year(): Check if date is within the next year

Check 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.386812

next_year_utc(): Check if date is within the next year in UTC

Check 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.386812
PreviousString ConditionsNextData Loaders

Last updated 1 year ago

Was this helpful?