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.
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!
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
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?
Hi Christopher,
Have you reviewed this article?
https://blog.prolecto.com/2015/01/30/netsuite-server-side-timezone-settings/
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 ?
Hello Nihal,
Did you see my article about server side dates here?
https://blog.prolecto.com/2015/01/30/netsuite-server-side-timezone-settings/