I need to set a date field at the beginning of eve...
# suitescript
a
I need to set a date field at the beginning of every month with the current date of that day. I am setting the field to the value of
new Date()
. It is a small script and I don't want to be busy importing moment.js, but I am concerned about server timezone issues may set it at the wrong date. What is the largest range of hours off that
new Date()
might be from my local timezone?
👀 1
b
what kind of scripts is it
the timezone used to set field values depends on the current user's timezone
s
If you are based in North America your server is likely West coast time, so 3 hours if you are on the east coast.
b
for scripts like user event scripts, it will be based off of the current user's selected timezone
for scripts like map reduce, it will be based off of the company's timezone
a
Oh. Its a map reduce
b
either way, the timezone used in the javascript is PST, suitescript utilities like N/format automatically convert that server pst timezone to values that match the current user's timezone
wont really help if you are doing something like setting to the first of the month
you would still need to set the hour to something that is the same day in both pst and your company's timezone
s
You can pretty easily see how far off the server is from your local timezone by firing off the MR. The details on the deployment MR Script Status Page will be in server time, not your local timezone. For example, I just fired off this MR (I'm on east coast), but the details for stages are in the server time.
m
Interesting article from @tdietrich on using suiteql for time/date functions https://timdietrich.me/blog/netsuite-suiteql-dates-times/.
c
Copy code
function getTodayInCurrentUserTimezone() {
        return format.parse({type: format.Type.DATE, value: format.format({type: format.Type.DATETIME, value: new Date()})});
    }
This will get you a date object in the current user's timezone. You gotta use N/format module.
a
Thanks everyone!
And I once again got 👀 from the legendary @erictgrubaugh!
@creece That's a great snippet. I am going to hold onto it. Its a map reduce so there isn't really a user. But @battk said above said that map/reduce scripts go based on company timezone so anyway it should be okay
z
@Marko Latinovic