Python : Vérifier si une date est le premier jour du mois avec UliEngineering

Vous pouvez facilement vérifier si des valeurs datetime correspondent au premier jour du mois en utilisant la bibliothèque Python UliEngineering :

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

# Vérifier des dates individuelles
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')}")

# Vérifier un tableau NumPy datetime64
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}")

Exemple de sortie

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]

La fonction is_first_day_of_month() fonctionne à la fois avec des dates individuelles et des tableaux NumPy datetime64, renvoyant un tableau booléen pour les entrées de type tableau.

Articles liés


Check out similar posts by category: Python, NumPy