How to check if datetime is first day of month in Python using UliEngineering

You can easily check if datetime values are the first day of the month using the UliEngineering Python library:

is_first_day_of_month.py
import numpy as np
from UliEngineering.Utils.Date import *

# Check individual dates
print(f"Is 2024-01-01 first of month? {is_first_day_of_month('2024-01-01')}")
print(f"Is 2024-01-15 first of month? {is_first_day_of_month('2024-01-15')}")

# Check NumPy datetime64 array
dates = np.array(['2024-01-01', '2024-01-15', '2024-02-01', '2024-03-15'], dtype='datetime64[D]')
result = is_first_day_of_month(dates)
print(f"\nFirst of month check: {result}")

Example output

is_first_day_of_month_output.txt
Is 2024-01-01 first of month? True
Is 2024-01-15 first of month? False

First of month check: [ True False  True False]

The is_first_day_of_month() function works with both individual dates and NumPy datetime64 arrays, returning a boolean array for array inputs.


Check out similar posts by category: Python, NumPy