How to extract day of month from NumPy datetime64 arrays in Python using UliEngineering
You can easily extract the day of month component from NumPy datetime64 arrays using the UliEngineering Python library:
extract_day_of_month.py
import numpy as np
from UliEngineering.Utils.Date import *
# Create a datetime64 array
dates = np.array(['2024-01-15', '2024-06-20', '2024-12-31'], dtype='datetime64[D]')
# Extract day of month
days = extract_day_of_month(dates)
print(f"Dates: {dates}")
print(f"Day of month: {days}")Example output
extract_day_of_month_output.txt
Dates: ['2024-01-15' '2024-06-20' '2024-12-31']
Day of month: [15 20 31]The extract_day_of_month() function returns a NumPy array containing the day of month (1-31) for each datetime64 value in the input array.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow