Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

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 LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

6 thoughts on “Working with NetSuite Date Fields in JavaScript

  1. 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!

    Reply
  2. 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?

    Reply
  3. 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 ?

    Reply

Leave a Reply

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