From 36f73d80e3315b81fdbfbc557cc20f9f3926495d Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Wed, 28 Oct 2020 16:20:50 +0200 Subject: [PATCH] Add to_iso_date --- snippets/to_iso_date.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 snippets/to_iso_date.md diff --git a/snippets/to_iso_date.md b/snippets/to_iso_date.md new file mode 100644 index 000000000..f192c4867 --- /dev/null +++ b/snippets/to_iso_date.md @@ -0,0 +1,21 @@ +--- +title: to_iso_date +tags: date,intermediate +--- + +Converts a date to its ISO-8601 represenation. + +- Use `datetime.datetime.isoformat()` to convert the given `datetime` object to an ISO-8601 date. + +```py +from datetime import datetime + +def to_iso_date(d): + return d.isoformat() +``` + +```py +from datetime import datetime + +to_iso_date(datetime(2020,10,25)) # 2020-10-25T00:00:00 +```