Skip to content

Commit 1741911

Browse files
authored
Create datetime-formatting.md
1 parent 41ff1a6 commit 1741911

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

posts/datetime-formatting.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Datetime Formatting
2+
3+
You are likely very familiar with formating datetimes in Excel, with format strings such as "MM-DD-YYYY".
4+
But Python has its own format strings that are, in my opinion, less intuitive.
5+
So I've built the below table to help you translate between your current knowledge and Python.
6+
7+
For all examples below I will use the datetime `6/3/2002 01:04:09`
8+
9+
| Excel Format | Python Format | Example |
10+
| -------- | -------- | -------- |
11+
| "M" | "%-m" | 6 |
12+
| "MM" | "%m" | 06 |
13+
| "MMM" | "%b" | Jun |
14+
| "MMMM" | "%B" | June |
15+
| "D" | "%-d" | 3 |
16+
| "DD" | "%d" | 03 |
17+
| "DDD" | "%a" | Fri |
18+
| "DDDD" | "%A" | Friday |
19+
| "YY" | "%y" | 02 |
20+
| "YYYY" | "%Y" | 2002 |
21+
| "H" | "%-H" | 1 |
22+
| "HH" | "%H" | 01 |
23+
| "M" | "%-M" | 4 |
24+
| "MM" | "%M" | 04 |
25+
| "S" | "%-S" | 9 |
26+
| "SS" | "%S" | 09 |

0 commit comments

Comments
 (0)