How to add ordinals to dates?

After some advice on how i convert dates i input to include ordinals.

For example
Data in reads - Thursday 6 December
I need to to read - Thursday 6th December (with the th super scripted)

Where would i look to do this? In my data-mapper with a new step?

Thanks in advance

Hi Rich,

Assuming your field in the data mapper is called Date. Add this script to your template.

function ordinal(n){return["st","nd","rd"][((n+90)%100-10)%10-1]||"th";}

var date = record.fields.Date.split(" ");
var day = parseInt(date[1]);

results.html(date[0] + " " + date[1] + '<sup>' + ordinal(day) + '</sup>' + " " + date[2]);

Modified script from my previous post.

Regards,
S

Hi Shane,

Sorry for late reply and thanks for the above…

I get the error shown below when i’ve added the script in

image

Any ideas?

You have to add that script to your template, not to your DataMapper config.

In here you mean?

Yep, that’s the spot. Make sure you modify the script to match your actual field name (Departure) instead of Date.

So i’d replace any occurrence of data for departure?

Also what would go in the Name & Find text boxes?

Hi Rich,

Sorry for only seeing this now. I have been busy wrapping my year up. I’m finally on leave but do have a few jobs that I will run from home.

Regarding my script. Yes, as Phil said, you have to add it to the template. I see you have a Text Script that is using a field called “DEPARTURE”. If that is the field you want to use then click the Expand button to convert the Text Script to JavaScript. Then delete all the code in there and replace it with my code. Then in my code replace the following line to use your DEPARTURE field. Like this.

Replace my code line:
var date = record.fields.Date.split(" ");

With this:
var date = record.fields.DEPARTURE.split(" ");

Regarding the Name box. Call it whatever you want. In the Find box you need to add the text that you use on your template for the script to find it and give it a value. You can put @DepartureDate@ in there for example. Then in your template you need to have a paragraph or positioned box or table that has @DepartureDate@ for the script to find it and replace it with the data you want once you click Preview in the Connect designer.

If you need a sample template and data mapper I can send one to you. Unfortunately this new site of Objectif Lune’s does not allow posting uploads of these files, so I will have to upload it elsewhere and share the link.

Regards,
S

Thanks for that reply Sharne,

i’ve followed all that but not getting any ordinals at all, see below screengrabs?

image

image

Never mind Sharne,

I believe its because we had the word DEPARTURE in uppercase?

In my sample mapper/template using field Date in the script. It made no difference if I changed it to DATE. Looks to me case did not matter in this instance.