Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python datetime with day date suffix format

#!/usr/local/bin/python3
from datetime import date
today = date.today()
date_string = today.strftime('%A, %B #, %Y')
day = today.day

if (3 < day < 21) or (23 < day < 31):
	day = str(day) + 'th'
else:
  suffixes = {1: 'st', 2: 'nd', 3: 'rd'}
  day = str(day) + suffixes[day % 10]

print(date_string.replace('#', day), end='')
Source by www.robjwells.com #
 
PREVIOUS NEXT
Tagged: #python #datetime #day #date #suffix #format
ADD COMMENT
Topic
Name
8+5 =