Printing ordinal date with linq

Hi
We are converting all our templates from mail merge to linq. I am not able to figure out how to print ordinal dates using linq.

In mail merge (mustache syntax), we used below syntax
{{ DateField @ "d" * Ordinal }} {{ DateField \@ "MMMM yyyy"}}
It prints something like 9th October 2016. We are formatting date field two times. First to get date only and next to convert it into ordinal.
How we can apply multiple formats in linq. Below expression is not working
<<[DateField] : "d" ordinal>>
<<[DateField]: "MMMM yyyy">>
Your help is much appreciated.

Even with mail merge (mustache syntax), I am not able to print superscripted ordinal

{{Field92 @ "MMMM"}} {{ Field92 \@ "d" \* Ordinal }}, {{ Field92 \@ "yyyy"}}

prints date as October 7th, 2016
but how to print October 7(th -> in superscript), 2016

Thanks,
John

Can you please point me what is incorrect in below syntax:

<<[DateField]:"MMMM":upper>>
<<[DateField]:"d":ordinal >>, <<[DateField] :"yyyy">>

I am getting below error:
Expression tag is not well-formed. Token ‘ordinal’ is unexpected.

Thanks
John

Hi John,

Thanks for your inquiry. The number format “ordinal” is used for only numbers. To format a date-time expression result, you can specify a format string as an element of the corresponding expression tag. Such format strings are the same as the ones that you pass to SimpleDateFormat constructors. Please refer to the following documentation link.

Outputting Expression Results

How to represent dates in ordinal using linq?

For example, to print date in format like October 9th, 2016
what are the possible options?

Hi John,
Thanks for your inquiry. Please check “Setting up Known External Types” from following link.
LINQ Reporting Engine API
In your case, we suggest you please use following code example to achieve your requirements. Hope this helps you.

DocumentBuilder builder = new DocumentBuilder();
builder.write("<<[MyDate.getOrdinalDate()]>>");

ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(MyDate.class);
engine.buildReport(builder.getDocument(), "");

builder.getDocument().save(MyDir + "Out v16.8.0.docx");
public class MyDate {

    public static String getDayNumberSuffix(int n) {
        switch (n % 10) {
            case 1:  return "st";
            case 2:  return "nd";
            case 3:  return "rd";
            default: return "th";
        }
    }

    public static String getOrdinalDate(){
        String dayNumberSuffix = getDayNumberSuffix(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd'" + dayNumberSuffix + "' yyyy");
        return  dateFormat.format(Calendar.getInstance().getTime());
    }
}