1

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...

Sean Bulley
  • 31
  • 1
  • 1
  • 3

1 Answers1

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
  • 2
    In 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
  • Yeah I added that moments after – Tim Nov 30 '14 at 14:45