Date to ISO format

Python, Date · Jan 7, 2021

Converts a date to its ISO-8601 representation.

  • Use datetime.datetime.isoformat() to convert the given datetime.datetime object to an ISO-8601 date.
from datetime import datetime

def to_iso_date(d):
  return d.isoformat()
from datetime import datetime

to_iso_date(datetime(2020, 10, 25)) # 2020-10-25T00:00:00

More like this

  • Date from ISO format

    Converts a date from its ISO-8601 representation.

    Python, Date · Jan 7, 2021

  • Add days to date

    Calculates the date of n days from the given date.

    Python, Date · Oct 28, 2020

  • Date range

    Creates a list of dates between start (inclusive) and end (not inclusive).

    Python, Date · Jan 7, 2021