Has anyone figured out how to convert date/time fi...
# general
m
Has anyone figured out how to convert date/time fields to local timezone in SuiteAnalytic Workbooks? I've found a
SESSIONTIMEZONE
function which correctly outputs the local timezone, but I'm struggling a little figuring out the formula to convert a date field in server (Pacific?) timezone
b
what are you doing to get a datetime (or is it a timestamp variant) in server time?
m
It's a Server Script Log Dataset. When I add the Date column directly I just get date without time. If I create a formula field with
{date}
as the formula, then the output includes the time
message has been deleted
message has been deleted
b
looks like a Date, and it looks like formulas in workbooks dont let you use cast
m
thanks
b
closest i got while looking minimally dumb is
NEW_TIME({date}, CASE TZ_OFFSET('AMERICA/LOS_ANGELES') WHEN '-07:00' THEN 'PDT' ELSE 'PST' END, TO_CHAR(CURRENT_TIMESTAMP, 'TZD'))
I couldnt find a pretty way to get PST vs PDT, so there is an ugly case statement in the middle
its unlikely you want this since NEW_TIME has limited timezone support
the more universal ugly solution is
{date} - TO_NUMBER(SUBSTR(TZ_OFFSET('AMERICA/LOS_ANGELES'), 1, 3)) / 24 + TO_NUMBER(SUBSTR(TZ_OFFSET(SESSIONTIMEZONE), 1, 3)) / 24 + TO_NUMBER(SUBSTR(TZ_OFFSET(SESSIONTIMEZONE), 5, 2)) / (24 * 60)
which essentially subtracts and adds timezone offsets
both solution look dumb when compared to using Datetime Expressions, which evidently the formulas in workbooks dont support
m
thanks @battk, works perfectly for what I need
b
i didnt take into account the sign of the offset for the minutes in the formula that adds offsets
m
thanks, i'm happy to harcode this one to my timezone so first formula works well enough for me