Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

Working with NetSuite Date Fields in JavaScript

NetSuite Technical

Tags: , , , , ,

It may not be obvious, but if you want to work with NetSuite API in JavaScript to push a date in a custom NetSuite date field, you simply can’t create a normal JavaScript date variable.  You must convert it first before you set the value.  Here is the code snippet:

var now = new Date();
var dnow = nlapiDateToString(now, 'datetimetz');
loadrec.setFieldValue('custentity[_your_date_field]', dnow);

Check out my other article on Parsing NetSuite DateStrings.  Need help to enhance NetSuite?  Contact us.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

6 thoughts on “Working with NetSuite Date Fields in JavaScript

  1. Peter Lu says:

    Thank you very much for your tips.

    I have also found couple more interesting things:

    1. nlapiDateToString(now) returns only the date part. ‘datetimetz’ is required to return the time part.

    2. nlapiStringToDate(‘5/12/2013 3:15:45 pm’) returns 5/12/2013 3:15:45. But nlapiStringToDate(‘5/12/2013 3:15:45 pm’,’datetimetz’) returns 5/12/2013 15:15:45.

    Cheers!

  2. Marty Zigman says:

    Thank you Peter,

    I may need to check this. Your example on number 2 seems to bring back the

      Date and the Time

    elements when not specifying the ‘datetimetz’ format parameter. Before I check this on my own, is that what you intended?

    Marty

  3. Christopher says:

    Hi Marty,

    Thank you for your your blog – NS development would be much harder without it!

    How can I get a datetime in my timezone?

  4. Nihal says:

    Hi Marty,

    I am getting date in unix format GMT+-00. When I am trying to create date by using the API :
    value = 1496341800000;
    nlapiDateToString(new Date(parseInt(value)), ‘date’);
    the Unix date is: 2/6/2017 and after converting it showing me 1/6/2017.

    why it showing one day before date ?

    Observation: May be it convert in server date ‘America/Los_​Angeles’.

    Can you please help me in this case how can i solved this problem ?

  5. Marty Zigman says:

    Hello Nihal,

    Did you see my article about server side dates here?

    https://blog.prolecto.com/2015/01/30/netsuite-server-side-timezone-settings/

Leave a Reply

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