Formatting Dates

To display "today's" date within the current locale, you can use:

Copy
[* USE date *]
[* date.format(date.now, '%a %d %b %y') *]

The sample output would be:

Copy
Output: Mon 28 Sep 15

Allowable Date Formats

This is a full list of what you can use for a date:

%a abbreviated weekday
%A weekday
%b abbreviated month
%B month
%C century number (0-99)
%d day of month (01-31)
%D American date style, m;d;Y
%e day of month (1-31)
%H hour (0-23)
%I hour, 12 hour clock (0-12)
%M minute
%m month number (1-12)
%p AM or PM according to locale
%R hour:minute/ %H:%M
%S second
%T hour:minute:second/ %H:%M:%S
%y year within century (e.g. 15)
%Y year with century (e.g. 2015)

FAQ

I'm receiving an error when formatting dates, is there anything I can do to solve this?

If you're receiving an error in the preview screen you can use the TRY/CATCH method. An example would look like:

Copy
[*
    TRY;
        date.format(data('subscription_expiry_date'), '%e %B');
    CATCH;
        'Default value'
    END;
*]

How do I output the dates in my data as DD-MM-YYYY?

To use dates in the platform they need to be imported as YYYY-MM-DD in your CSV. So if your dates are dash separated, you can output it as DD-MM-YYYY using the .split method:

Copy
[* 
    newdate = data(1,'date').split('-');
    newdate.2 _ '/' _ newdate.1 _ '/' _ newdate.0;
*]

Output: DD/MM/YYYY

Note: The split method requires a separation character (whether it is a dash, comma, space or slash). This should then be identified in the directive.