Skip to main content

getOrdinalForDay

getOrdinalForDay returns the ordinal suffix ('st', 'nd', 'rd' or 'th') for a given day of the month. It's typically used when formatting dates for display — for example turning 21 into 21st.

Note that it returns only the suffix, so you concatenate it onto the day yourself.

Usage examples

Basic

window.BAO.utils.getOrdinalForDay(1)  // 'st'
window.BAO.utils.getOrdinalForDay(2) // 'nd'
window.BAO.utils.getOrdinalForDay(3) // 'rd'
window.BAO.utils.getOrdinalForDay(11) // 'th'
window.BAO.utils.getOrdinalForDay(21) // 'st'

Building a display date

const day = 23
const label = `${day}${window.BAO.utils.getOrdinalForDay(day)} July` // '23rd July'