# How to Format Standard and Custom Date Fields via Scripts

## If you need to change the standard date format received via scripts, you can use either of these two options to change the date format.

### 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.

Infoplus Support can help with general questions about how scripting works. For help with a specific script or its outputs, you will need to submit a Pro Services request for paid support. Pro Service request form can be found [here](/content/submit-pro-service-request?hsCtaTracking=9b08eaf8-65c7-4785-9404-bdc0846e5a1f%7C5a70c67a-39d4-4945-9e85-fa3813ebc11b&hsLang=en/index.html).

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.

|     |     |
| --- | --- |
|  | vardateToFormat=record.DateToFormat;// or record.customFields.get("DateToFormat"); |
|  | varcurrentDate=newDate(dateToFormat);//use your date here |
|  | currentDate.toLocaleDateString('en-US');// "en-US" gives date in US Format - mm/dd/yy |

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

|     |     |
| --- | --- |
|  | varstartDate=record.dateField// or record.customFields.get("dateField"); |
|  | varconvertedStartDate=newDate(startDate); |
|  | varmonth=convertedStartDate.getMonth()+1 |
|  | varday(date)=convertedStartDate.getDate(); |
|  | varyear=convertedStartDate.getFullYear(); |
|  | varshortStartDate=month+"/"+day+"/"+year; |

**Be mindful of using .getDate vs .getDay**

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.
