diff --git a/.zk/notebook.db b/.zk/notebook.db index 64b22f2..1eee746 100644 Binary files a/.zk/notebook.db and b/.zk/notebook.db differ diff --git a/zk/Dates_in_Python.md b/zk/Dates_in_Python.md index d3ac937..ff53a23 100644 --- a/zk/Dates_in_Python.md +++ b/zk/Dates_in_Python.md @@ -68,9 +68,21 @@ print("Minute:", some_datetime.minute) print("Second:", some_datetime.second) ``` -### Formatting Datetime Objects +### Formatting Datetime Objects: `strftime` -You can format datetime objects to strings using the `strftime` method. +The `strftime` method (_string format time_) converts a datetime object to a +string according to the specified format. + +In the example below we use `strftime` to express the current date as YYYY-MM: + +```python +now = datetime.now() +formatted = now.strftime('%Y-%m') +print(formatted) +# 2024-06 +``` + +Another example, for YYYY-MM-DD H:M:S: ```python formatted_datetime = some_datetime.strftime('%Y-%m-%d %H:%M:%S')