Files
30-seconds-of-code/snippets/to-iso-date.md
2023-04-28 22:24:23 +03:00

470 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Date to ISO format snippet
date
succulent-red-light 2021-01-07T23:30:28+02:00

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