How to generate datetime array for days in Python using UliEngineering
You can easily generate a NumPy datetime64 array for a range of days using the UliEngineering Python library:
generate_days.py
import numpy as np
from UliEngineering.Utils.Date import *
# Generate datetime array for January 2024
days = generate_days("2024-01-01", "2024-01-31")
print(f"Days in January 2024: {len(days)}")
print(f"First day: {days[0]}")
print(f"Last day: {days[-1]}")
# Generate datetime array for a week
days = generate_days("2024-01-01", "2024-01-07")
print(f"\nDays in a week: {days}")Example output
generate_days_output.txt
Days in January 2024: 31
First day: 2024-01-01
Last day: 2024-01-31
Days in a week: ['2024-01-01' '2024-01-02' '2024-01-03' '2024-01-04' '2024-01-05'
'2024-01-06' '2024-01-07']The generate_days() function returns a NumPy datetime64 array containing all days from the start date (inclusive) to the end date (inclusive).
Related posts
- How to generate datetime array for years in Python using UliEngineering
- How to generate datetime array for months in Python using UliEngineering
- How to extract months from NumPy datetime64 arrays 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