I've got a date in the format day=30, month=11, year=2014. How can I use python to return this in a worded format? Example Sunday 30th November 2014. I can't find any datetime format that this works for...
Asked
Active
Viewed 1.7k times
1
-
can you show us an actual example of your datetime object? – agconti Nov 30 '14 at 14:39
-
similar question: http://stackoverflow.com/questions/311627/how-to-print-date-in-a-regular-format-in-python – user2314737 Nov 30 '14 at 14:42
1 Answers
12
You can use the following format for strftime
:
In [1]: from datetime import date
In [2]: date(day=30, month=11, year=2014).strftime('%A %d %B %Y')
Out[2]: 'Sunday 30 November 2014'
Adding the proper suffix to the day number is more complicated:

Community
- 1
- 1

Lev Levitsky
- 63,701
- 20
- 147
- 175
-
2In addition, `%dth` will give `30th` instead of `30` (only makes sense for dates that end with 'th') – Tim Nov 30 '14 at 14:43
-
Link to python docs with complete list of `strftime ` formatting directives https://docs.python.org/2/library/datetime.html?highlight=date#strftime-strptime-behavior – NickAb Nov 30 '14 at 14:44
-
@TimCastelijns Yes, but unfortunately that will be incorrect for days from `1` to `3` and some others. – Lev Levitsky Nov 30 '14 at 14:45
-