The Python documentation details the date format,
however the strings used for strftime
and strptime
are built from the following directives.
Table 13.2. Date Format Directives
Directive | Meaning | Example |
---|---|---|
%d | Day of the month as a zero-padded decimal number | 01, 02, ..., 31 |
%m | Month of the year as a zero-padded number | 01, 02, ..., 12 |
%y | 2-digit year as a zero-padded number | 00, 01, ... 99 |
%Y | 4-digit year as a zero-padded number | 0000, ..., 2020, ...., 9999 |
%H | 24-hour clock Hour as a zero-padded number | 00, 01, ..., 23 |
%I | 12-hour clock Hour as a zero-padded number | 00, 01, ..., 12 |
%p | AM/PM (or local equivalent) | AM, PM |
%M | Minute as a zero-padded number | 00, 01, ..., 59 |
%S | Second as a zero-padded number | 00, 01, ..., 59 |
Table 13.3. Common Examples of Date Strings
String | Output Example |
---|---|
%Y-%m-%d | 2019-12-31 |
%H:%M:%S | 23:59:59 |
%m/%d/%y %H:%M:%S | 12/31/19 23:59:59 |