How to check if datetime is first day of week in Python using UliEngineering
You can easily check if datetime values are the first day of the week (Monday) using the UliEngineering Python library:
is_first_day_of_week.py
import numpy as np
from UliEngineering.Utils.Date import *
# Check individual dates
print(f"Is 2024-01-01 first of week? {is_first_day_of_week('2024-01-01')}")
print(f"Is 2024-01-08 first of week? {is_first_day_of_week('2024-01-08')}")
# Check NumPy datetime64 array
dates = np.array(['2024-01-01', '2024-01-02', '2024-01-08', '2024-01-09'], dtype='datetime64[D]')
result = is_first_day_of_week(dates)
print(f"\nFirst of week check: {result}")Example output
is_first_day_of_week_output.txt
Is 2024-01-01 first of week? True
Is 2024-01-08 first of week? True
First of week check: [ True False True False]The is_first_day_of_week() function works with both individual dates and NumPy datetime64 arrays, returning a boolean array for array inputs.
Related posts
- How to check if datetime is first day of month in Python using UliEngineering
- How to extract day of week from NumPy datetime64 arrays in Python using UliEngineering
- How to check if datetime is year change in Python using UliEngineering
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow