Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python how to return date as words?

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

like image 984
Sean Bulley Avatar asked Apr 01 '26 17:04

Sean Bulley


1 Answers

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:

  • python format datetime with "st", "nd", "rd", "th" (english ordinal suffix) like PHP's "S"
  • Date Ordinal Output?
like image 161
Lev Levitsky Avatar answered Apr 04 '26 07:04

Lev Levitsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!