pcmdi_metrics.utils.date_to_str
- pcmdi_metrics.utils.date_to_str(date_obj)[source]
Convert a date object to a string in ‘YYYY-MM-DD’ format.
- Parameters:
date_obj (
datetime.datetime
orcftime.datetime
) – The date object to convert.- Returns:
str
– The date in ‘YYYY-MM-DD’ format.
Notes
This function handles both standard Python datetime objects and cftime datetime objects.
Examples
>>> from pcmdi_metrics.utils import date_to_str >>> from datetime import datetime >>> date_to_str(datetime(2001, 1, 1)) '2001-01-01' >>> import cftime >>> date_to_str(cftime.DatetimeGregorian(2001, 1, 1)) '2001-01-01'