format.parse returning string with perfectly valid...
# ask-stanley-ai
c
format.parse returning string with perfectly validate date string '10/1/2025'
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that the issue is with parsing a date string into a date object in SuiteScript. The
format.parse()
function in SuiteScript parses a string using the date format set in the user's preferences, which can lead to inconsistencies if the date string format doesn't match the user's preferences. One solution is to use standard JavaScript functions to create a new Date object. Here's an example:
Copy code
javascript
var reqShipDateSplit = item_req_ship_date.split("/"); // free-form -text field
var expected_ship_date = new Date();
ExpectedShipDate = reqShipDateSplit[0]+'/'+reqShipDateSplit[1]+'/'+reqShipDateSplit[2];
expected_ship_date.setDate(reqShipDateSplit[0]);
expected_ship_date.setMonth(reqShipDateSplit[1] - 1);
expected_ship_date.setFullYear(reqShipDateSplit[2]);
ExpectedShipDate = format.format({value: expected_ship_date,type: format.Type.DATE,timezone: format.Timezone.AMERICA_LOS_ANGELES});
Another solution is to use the moment.js library to parse the date. However, if the date string is not in a format that NetSuite recognizes, you may need to manipulate the string before parsing it. For example, if the date string is in GMT or UTC timezone, you can use:
Copy code
javascript
new Date('2019-07-24T13:06:16.9591051'.substr(0, 23) + 'Z')
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830200076
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829467654
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.82800281
Please provide your feedback on this answer.