can we format Date object to MM/DD/YYYY via format...
# suitescript
a
can we format Date object to MM/DD/YYYY via format.parse method?
s
What do you mean by set the Date format? Set the format of what?
s
I think he means the date format as in if it's MM/DD/YYYY or DD/MM/YYYY etc? i think it's usually tied to preferences? (user/company?)
a
@Sandii format of a JS Date Object
s
I would not recommend not trying to do that with js date object, just use moment or some other date js library of your chosing.
a
yes, but is that possible with parse?
s
I am not a fan of the
N/format
module at all, I would personally just use
moment().format()
a
thanks
s
To do it very simply in moment would be
moment(yourDate, oldFormat).format(newFormat)
🙌 1
b
N/format has a very specific purpose, to changes values back and forth between their text representation in the current netsuite account
you will be disappointed in it when using it for anything else
s
@Ali this is what I'm using with moment, just load it as a library in your define/function like you load the N/modules and you're good to go https://momentjs.com/docs/#/parsing/string-format/ otherwise if you use it just with format.format or format.parse it's user settings - usually gets in the way in TBA and restlets too - just use moment to change the defined string input to a date object, then before you set the value in the record, use the standard NS format module and it'll work most of the time!