Date Format for HR Document Templates

Georgi Ankov
Tera Contributor

Hi everyone, I am having an issue where the date is being added to our HR Document Templates in the format "DD-MM-YYYY" (e.g. 19-05-2023), but I need in the format "DD MMM YYYY" (e.g. 19 May 2023). Is there a way of getting this format from all date fields when added to HR Document Templates?

2 REPLIES 2

shirisha5
Tera Contributor

@Georgi Ankov  "Have you found a solution for this?"

Juhi Poddar
Kilo Patron

Hello @shirisha5 @Georgi Ankov 

 

I maybe late to answer this post, but since it is unanswered I would like to give a solution to this. 

Steps to meet the requirement:

  • Create a Script Include that will format dates in the "DD MMM YYYY" format. 

 

var HRDateFormatter = Class.create();
HRDateFormatter.prototype = {
    initialize: function() {},

    formatDate: function(date) {
        if (!date) return '';
        var glideDate = new GlideDateTime(date);
        return glideDate.getDayOfMonthLocalTime() + ' ' +
               glideDate.getMonthNameLocalTime() + ' ' +
               glideDate.getYearLocalTime();
    },

    type: 'HRDateFormatter'
};
  • Call this HRDateFormatter Script Include to format the date fields when inserting them into your document. For example, if your date field is called start_date:

 

 

var formattedDate = new HRDateFormatter().formatDate(current.start_date);

 

  • 'formattedDate' will provide the date in "DD MMM YYYY" format, like "19 May 2023."

"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar