I have this value in the date field below. Now i w...
# suitescript
v
I have this value in the date field below. Now i want to change it to mm/dd/yyyy format. how can this be achieved? Thu Feb 24 2022 000000 GMT+0100 (Central European Standard Time)
a
Copy code
let dateStr = now.toLocaleDateString();

let dateStr =  `${now.getMonth()+1}/${now.getDate()}/${now.getFullYear()}`;
either should work but depending on context the 2nd version is probably "safer", and given you're asking the question, do it the 2nd way 🙂
n
You can use the N/format module to convert your date object into the string you want. https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4388721627.html
a
you can probably also use the NS format module? but again, context matters
💯 1
t
Copy code
const convertDateTimeToDate = (dateTimeStr) => {
            let date = new Date(dateTimeStr);
            let month = (date.getMonth() + 1).toString().padStart(2, '0');
            let day = date.getDate().toString().padStart(2, '0');
            let year = date.getFullYear();
            return `${month}/${day}/${year}`;
        };
a
weird that you're in CST and you want the date in US format 😛
v
Thank you all, it is working fine with toLocaleDateString()
a
it might now matter, but that will be environment dependent, and if its running in a client context, it will be, where is this person located, dependent