Hi All, I'm working on a requirement where a "stri...
# suitescript
d
Hi All, I'm working on a requirement where a "string date" is set on a free-form text by a third party I'll have to convert it to date format and set the value into a date field . I'm using format.date but it is throwing me error any ideas?
w
how is the date formatted and how are you parse:ing it?
and what is the error that is thrown?
As the function format.parse() parses a string using the date format set in the preferences of the user, you run the risk of having a different format compared to the field-value. If you know the format, I'd use standard javascript functions to create a "new Date()" instead. Or use the moment.js library to parse the date instead.
d
@Watz converting to date format using new Date() worked for me here's how I did it 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}​​​​​);