Hello Guys, While formating the date using .format...
# suitescript
a
Hello Guys, While formating the date using .format function in SuiteScript 2.0, I am getting error "INVALID_TYPE_1_USE_2". How can I resolve it?
b
share the code
a
try { log.debug('DEBUG','startDate: ' + startDate); var splitBlank = startDate.split(' '); log.debug('DEBUG','splitBlank[0]: ' + splitBlank[0]); var splitData = splitBlank[0].split('-'); log.debug('DEBUG','splitData[0]: ' + splitData[0] + ' :: splitData[1]: ' + splitData[1] + ' :: splitData[2]: ' + splitData[2]); var nsDate = [splitData[1],splitData[0],splitData[2]].join('/'); log.debug('DEBUG','nsDate: ' + nsDate); var parsedDateStringAsRawDateObject = format.parse({ value: nsDate.trim(), type: format.Type.DATE }); log.debug('DEBUG','parsedDateStringAsRawDateObject: ' + parsedDateStringAsRawDateObject.toString()); var formattedDateString = format.format({ value: parsedDateStringAsRawDateObject, type: format.Type.DATE }); log.debug('DEBUG','formattedDateString: ' + formattedDateString.toString()); return [parsedDateStringAsRawDateObject, formattedDateString]; } catch(e) { log.error('ERROR','Exception in date: ' + e.toString()); }
b
one of the weaknesses of format.parse is that it outputs the input if the input is invalid
are you sure parsedDateStringAsRawDateObject is a Date
you are probably wasting your time using both parse and format, the two are inverses of each other
a
@battk When I select few records from csv file and create a new CSV file, then importing that file in NetSuite via SuiteScript, getting date format "DD-MM-YYYY". But when I imported the CSV file which was given by the client than getting date value in "YYYY-MM-DD" format. Can you please let me know why I am getting different format?
message has been deleted
b
excel has date formatting preferences
use a text editor to look at the raw output
a
Correct... thanks @battk
b
the usual recommendation is using moment timezone to format your string into a Date
👍 1
N/format is only good for strings to go to and from netsuite
a
Okay