The error is telling you that one of the parameters is not of type Date. The CalendarApp.createEvent method expects a signature like this:
createEvent(title, startTime: Date, endTime: Date)
In your case, one of the date parameters (most likely startTime) is being passed as a string rather than a Date object.
What’s Happening
- Even though the cells are formatted as dates in your spreadsheet, using getValues() sometimes returns them as strings if they're not properly recognized by Apps Script.
- Thus, when you pass eventos[0] or eventos[1] to createEvent, you might be passing a string.
How to Fix It
-
Confirm Date Formatting in the Spreadsheet:
Ensure that the cells in columns A and B are truly formatted as dates.
-
Convert the Values to Date Objects:
Even if the cells are formatted as dates, you can enforce conversion in your script to avoid any type mismatch. For example:
function SheetsToCalendar() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var hojaCitas = spreadsheet.getSheetByName("BBDD_Citas");
var configCalendar = spreadsheet.getSheetByName("Config");
var calendarID = configCalendar.getRange("C2").getValue();
var eventCal = CalendarApp.getCalendarById(calendarID);
var fechaHora = hojaCitas.getRange("A2:B1000").getValues();
var titulos = hojaCitas.getRange("F2:F1000").getValues();
for (var x = 0; x < fechaHora.length; x++) {
var eventos = fechaHora[x];
var nombres = titulos[x];
// Convert to Date objects in case they are strings
var startTime = new Date(eventos[0]);
var endTime = new Date(eventos[1]);
var titulo = nombres[0];
eventCal.createEvent(titulo, startTime, endTime);
}
}
Note: I also adjusted the order of parameters in createEvent to match the documented signature (title, start, end).
Summary
The error occurs because at least one of your date parameters is a string. Make sure your spreadsheet cells are correctly formatted as date values, and use new Date() conversion in your code to enforce the correct type.