To format the date using ‘N/format’ in NetSuite

/**

* @NApiVersion 2.x

* @NScriptType Suitelet

*/

define(['N/format', 'N/log'], function(format, log) {

function onRequest(context) {

if (context.request.method === 'GET') {

var inputDate = '2/28/2025'; // MM/DD/YYYY format

try {

// Parse using NetSuite standard method

var parsedDate = format.parse({

value: inputDate,

type: format.Type.DATE

});

// Convert to strict ISO format (YYYY-MM-DD) using standard Date

var isoFormatted = parsedDate.toISOString().split('T')[0];

//  Log and output

log.debug('ISO Formatted Date', isoFormatted);

context.response.write('Formatted Date: ' + isoFormatted);

} catch (e) {

log.error('Parse Error', e.message);

context.response.write('Error: ' + e.message);

}

}

}

return {

onRequest: onRequest

};

});

Leave a comment

Your email address will not be published. Required fields are marked *