Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Importing Google Calendar into Google Sheets and Account for Daylight Savings Time

I copied some code from this website so I can import a google calendar into google sheets. I am not a programmer, I know just enough to be dangerous. I am wondering if there is a line(s) of code that can be added to the script below that will account for Daylight Savings Time.

I live in the Central Time Zone (Missouri). My computer is set to Central Time Zone-Chicago. Now that DST is here, all the times that are imported from Google Calendar into Google Sheets are 1 hour behind what they actually show in Google Calendar. Is there a line(s) of code that can be added to this script to account for DST and pull in the correct times? Any help is greatly appreciated. Thanks, Eric

function importGoogleCalendar() {
var sheet = SpreadsheetApp.getActiveSheet();
var calendarId = sheet.getRange('B1').getValue().toString();
var calendar = CalendarApp.getCalendarById(calendarId);

// Set filters
var startDate = sheet.getRange('B2').getValue();
var endDate = sheet.getRange('B3').getValue();
var searchText = '';

// Print header
var header = [["Title", "Location", "Start", "End", "Duration"]];
var range = sheet.getRange("A6:E6");
range.setValues(header);
range.setFontWeight("bold")

// Get events based on filters
var events = (searchText == '') ? calendar.getEvents(startDate, endDate) : calendar.getEvents(startDate, endDate, {search: searchText})

// Display events
for (var i=0; i<events.length; i++) {
var row = i+7;

var details = [[events[i].getTitle(), events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(), '']];

range = sheet.getRange(row,1,1,5);
range.setValues(details);

/ Format the Start and End columns
var cell = sheet.getRange(row, 3);
cell.setNumberFormat('mm/dd/yyyy hh:mm');
cell = sheet.getRange(row, 4);
cell.setNumberFormat('mm/dd/yyyy hh:mm');

// Fill the Duration column
cell = sheet.getRange(row, 5);
cell.setFormula('=(HOUR(D' + row + ')+(MINUTE(D' +row+ ')/60))-(HOUR(C' +row+ ')+(MINUTE(C' +row+ ')/60))');
cell.setNumberFormat('0.00');
}
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check your script timezone.

To do that, go to settings in your script editor (select the gear on the left hand side) and active the third checkbox. Return to the script editor and edit appsscript.json. Change as needed the time zone (America/Chicago).

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!