SuiteScript 2.0 local DateTime or DateTime Math

My server is in the Northwest region but our corporate office is on the east coast…

I need to be able to record a datetime within a suitescript 2.0 scheduled script.

How can I either…

 

  1. retrieve the current, local (Eastern) timezone datetime, or…
  2. retrieve the current datetime and add 3 hours to it…

 

Thanks

Beginner Asked on November 1, 2019 in SuiteScript.
Add Comment
3 Answer(s)

I use something like this:

 

var system_offset = 420; // System offset from GMT, in minutes (for us, we are in Pacific time)

var user_offset = new Date().getTimezoneOffset() – system_offset; // User offset from System offset

 

You can then use user_offset for your date calculations.

Beginner Answered on November 1, 2019.

So, on the east coast that would be 300…

…but that would not account for daylight savings time if it is in minutes… correct?

on November 1, 2019.

Correct.  At the moment I have to change that system_offset value twice a year.  *sigh*

on November 1, 2019.
Add Comment

If I’ve understood your question correctly, maybe  this SuiteAnswer will help?

https://netsuite.custhelp.com/app/answers/detail/a_id/32122

(btw it mentions SS1.0 but that’s easily re-written as SS2.0)

Rookie Answered on November 1, 2019.

Interesting…but it seems a bit of a hack to create a custom record for something that should be doable within code…

on November 1, 2019.
Add Comment

I found the answer I needed….

Since I know that my server time is Pacific and I am always 3 hours ahead in Eastern, even with Daylight Savings Time…

var date = new Date();
date.setHours(date.getHours() + 3);

…which gets the current hours of the variable date and sets it to +3 hours…
Although this particular script should never run after 9pm, from what I have read, if the above “+3” returns an hour over 23, it will increment the date and the extra hours so it should be valid for any time reference…
Beginner Answered on November 1, 2019.

This works. Additionally, I recommend the momentjs library for any handling of dates. Just makes things pretty easy.

on November 4, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor