From 7b7a3471172f5bfe923221226bc6393ce93e24ac Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Wed, 28 Oct 2020 16:20:04 +0200 Subject: [PATCH] Add from_iso_date --- snippets/from_iso_date.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/from_iso_date.md diff --git a/snippets/from_iso_date.md b/snippets/from_iso_date.md new file mode 100644 index 000000000..99e675fea --- /dev/null +++ b/snippets/from_iso_date.md @@ -0,0 +1,19 @@ +--- +title: from_iso_date +tags: date,intermediate +--- + +Converts a date from its ISO-8601 represenation. + +- Use `datetime.datetime.fromisoformat()` to convert the given ISO-8601 date to a `datetime` object. + +```py +from datetime import datetime + +def from_iso_date(d): + return datetime.fromisoformat(d) +``` + +```py +from_iso_date('2020-10-28T12:30:59.000000') # 2020-10-28 12:30:59 +```