• Instructions to Ask a Question

    Click on the "Ask a Question" button and select the application for which you would like to ask questions.

    We have 5 different products namely - Pabbly Connect, Pabbly Subscription Billing, Pabbly Email Marketing, Pabbly Form Builder, Pabbly Email Verification.

    The turnaround time is 24 hrs (Business Hours - 10.00 AM to 6.00 PM IST, Except Saturday and Sunday). So your kind patience will be highly appreciated!

    🚀🚀Exclusive Discount Offer

    Just in case you're looking for any ongoing offers on Pabbly, you can check the one-time offers listed below. You just need to pay once and use the application forever -
     

    🔥 Pabbly Connect One Time Plan for $249 (🏆Lifetime Access) -  View offer 

    🔥 Pabbly Subscription Billing One Time Plan for $249 (🏆Lifetime Access) - View offer

convert numbers to ordinal numbers

Stuart

Member
Hi,
Is there any way to convert numbers to ordinal form?
That is 1 > 1st, 2 > 2nd 3 > 3rd, 123 > 123rd.
I could do it with a lookup table for 1 and 2 but that's not a free task!
 

Fagun Shah

Well-known member
Try this JS code action instead, which converts multiple comma separated cardinal numbers to ordinal numbers -



function convertToOrdinal(numbers) {
if (!Array.isArray(numbers)) {
return ['Input should be an array of numbers'];
}

const ordinalForms = [];

for (const number of numbers) {
if (typeof number !== 'number') {
ordinalForms.push('Not a number');
} else if (number % 1 !== 0) {
ordinalForms.push('Not an integer');
} else if (number >= 11 && number <= 13) {
ordinalForms.push(number + 'th');
} else {
switch (number % 10) {
case 1:
ordinalForms.push(number + 'st');
break;
case 2:
ordinalForms.push(number + 'nd');
break;
case 3:
ordinalForms.push(number + 'rd');
break;
default:
ordinalForms.push(number + 'th');
}
}
}

return ordinalForms;
}

// Example usage:
const result = convertToOrdinal([12, 1, 13]);//Replace 12,1,13 with your numbers
return (result);


1698807448540.png
 

wibbler

Member
Hi I would actually like the reverse! Converting Ordinal dates (1st, 2nd...) in a form input to 1,2... in Pabbly so that it can be processed correctly by the Date Formatter. Is there a javascript for this too?
 

wibbler

Member
Thanks! However, I have this:

Jan 4th 2025

And I want to make it

Jan 4 2025

with one Pabbly step. Is that possible with your solution? I think i'd have to isolate the date, strip out with regex, and then put the date together again.
 

Stuart

Member
you could do that just change the last line from
JavaScript:
console.log(result)
to
JavaScript:
return(result)
but it is a paid task.
you could do it with free tasks but I think it will be 2 steps (split, then regex).

1736276125076.png
 

wibbler

Member
Thanks again! I think from your wording, there is no free way to do this in one step within Pabbly?
 

ArshilAhmad

Moderator
Staff member
Yes, if you want to use regex to strip out 'th' or 'nd', you would have to split the date and then put it back together once it's stripped of the unwanted characters

===============================================================

Or you can also use two 'Replace Text' action steps to remove the unwanted characters.

 

wibbler

Member
Thanks - I think with Replace Text there would need to be multiple steps to remove "th", "nd", "st", am I right?
 

ArshilAhmad

Moderator
Staff member
Yes, you need three 'Replace Text' action steps in your workflow to achieve the desired result. Also, you have to map the result of one Text Formatter to another. Check out the workflow shared below.

 
Top