Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how write a date with th and nd in python

from datetime import datetime as dt

def suffix(d):
    return 'th' if 11<=d<=13 else {1:'st',2:'nd',3:'rd'}.get(d%10, 'th')

def custom_strftime(format, t):
    return t.strftime(format).replace('{S}', str(t.day) + suffix(t.day))

print custom_strftime('%B {S}, %Y', dt.now())
Comment

how write a date with th and nd in python

from datetime import datetime as dt

def suffix(d):
    return 'th' if 11<=d<=13 else {1:'st',2:'nd',3:'rd'}.get(d%10, 'th')

def custom_strftime(format, t):
    return t.strftime(format).replace('{S}', str(t.day) + suffix(t.day))

print custom_strftime('%B {S}, %Y', dt.now())
Comment

PREVIOUS NEXT
Code Example
Python :: python you bad 
Python :: what is the difference between max-width and flex-basis 
Python :: d2h recharge plan list 2022 telugu 
Python :: pygame download for python 3.10 
Python :: convolutional layer of model architecture pass input_shape 
Python :: Add dj_database_url on heroku or production 
Python :: #Combine two sets on python with for loop 
Python :: while loop choosing numbers 
Python :: PyQt5 change keyboard/tab behaviour in a table 
Python :: how to select specific column with Dimensionality Reduction pyspark 
Python :: how to get random images frrom quotefancy python 
Python :: pie chart labeling 
Python :: pool.map multiple arguments 
Python :: reset csv.DictReader python 
Python :: pandas dtodays date csv 
Python :: with statement python 3 files 
Python :: python record screen and audio 
Python :: django column to have duplicate of other 
Python :: form a chakravyuh matrix python 
Python :: lekht valenca poland 
Python :: pylint no name in module opencv 
Python :: list comprehensions with dates 
Python :: paschat opposite sanskrit 
Python :: dict_leys to list 
Python :: get the hour of every instance of the date_time 
Python :: python code to print fibonacci series 
Python :: Left fill with zeros 
Python :: csv.DictReader Skip Lines 
Python :: django force download file 
Python :: mechanize python XE #29 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =