How to Format Standard and Custom Date Fields via Scripts

How to Format Standard and Custom Date Fields via Scripts

There may be times when you want/need to format a date field within Infoplus. By default, date fields are returned in the following format: (Year-Month-DayHour-Minute-Second) 2019-11-02T00:00:00.000Z.  While this is useful for some purposes, there may be times you want to use a short or custom date format. 

Due to the ever-changing nature of writing and maintaining scripts, Infoplus does not provide support in this area. We recommend someone in your IT Department handles scripting requests internally so that you keep all control over the process.


We have two simple solutions you can use to format your dates any way you want. 


The first method is to use .toLocaleDateString

(new Date()).toLocaleDateString('en-US');

Simply place the date you want to format in the open parentheses of the new Date object.  

The second method is to use .getDate(), .getMonth() and .getYear() to create your own custom format. 


Be mindful of using .getDate vs .getDay

Here are more date methods that can be used:


Here are more date methods that can be used:

 

Method Description
getFullYear() Get the year as a four digit number (yyyy)
getMonth() Get the month as a number (0-11)
getDate() Get the day as a number (1-31)
getHours() Get the hour (0-23)
getMinutes() Get the minute (0-59)
getSeconds() Get the second (0-59)
getMilliseconds() Get the millisecond (0-999)
getTime() Get the time (milliseconds since January 1, 1970)
getDay() Get the weekday as a number (0-6)
Date.now() Get the time. ECMAScript 5.