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
- 2.0 Build
- 1.0 Build
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'
getOrdinalForDay(1) // 'st'
getOrdinalForDay(2) // 'nd'
getOrdinalForDay(3) // 'rd'
getOrdinalForDay(11) // 'th'
getOrdinalForDay(21) // 'st'
Building a display date
- 2.0 Build
- 1.0 Build
const day = 23
const label = `${day}${window.BAO.utils.getOrdinalForDay(day)} July` // '23rd July'
const day = 23
const label = `${day}${getOrdinalForDay(day)} July` // '23rd July'