Help

Re: Timezones - Not sure why script outputs GMT?

Solved
Jump to Solution
1965 0
cancel
Showing results for 
Search instead for 
Did you mean: 

I’m not too sure where I’m going wrong. The Javascript examples I’ve read indicate that this should work, but Airtable isn’t processing them as I’d hoped - and judging from the results I’ll need to modify my script somehow.

Although the Automation triggers at the correct local time, it certainly doesn’t pass the local time as an input into the script - which isn’t a problem so long as we can easily process it to the correct time within the script, which is where I’m stuck.

//Trigger executes 7am daily and provides the _input_date to the script, but it is using yesterdays date (even though Airtable trigger states it is using local time?), so attempting to align it with local time via JS below

let rightNow = input.config()._input_date;
var date = new Date(rightNow);

let today = new Date()
let string = today.toLocaleDateString()
let correct = new Date(string)

console.log(date.getTimezoneOffset());
console.log(date.toLocaleTimeString('en-AU'));
console.log(correct)

image

image

Appreciate any help. This is messing with me big time. :face_with_raised_eyebrow:

11 Replies 11
Justin_Barrett
18 - Pluto
18 - Pluto

Very clever solution, @kuovonne! Not sure why it didn’t occur to me sooner to use a formula, but it works very well.

Because of how the API that I’m currently using is returning the time difference and how I’m using that difference in my script, I tweaked the output and added some things to return the same format as the API. In the screenshot below from my [Setup] table, left is the API return, and right is the output from my tweaked formula.

Screen Shot 2021-09-22 at 8.44.26 AM

"-0" & ABS(DATETIME_DIFF(
    DATETIME_PARSE(
        DATETIME_FORMAT(
            SET_TIMEZONE(NOW(), "America/Los_Angeles"), 
            "YYYY-MM-DD-HH-mm"
        ), 
        "YYYY-MM-DD-HH-mm"
    ), 
    NOW(), 
    "hours"
)) & ":00"

That’s a great workaround. Still frustrating that I need to create two new fields to support a workflow, I wish I could do this all via the Automation Script routine without the need for an external reference/field.