Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda