JavaScript date formatting function fails in Zapier with getFullYear error

I’m having trouble with a date formatting function that works fine in my local development environment but throws an error when I run it in Zapier. The error message says TypeError: dateobj.getFullYear is not a function, which suggests the input isn’t being recognized as a proper Date object.

Here’s my current code:

function formatDateTime(inputDate, pattern) {
  var yr = inputDate.getFullYear();
  var mon = ("0" + (inputDate.getMonth() + 1)).slice(-2);
  var day = ("0" + inputDate.getDate()).slice(-2);
  var hr = ("0" + inputDate.getHours()).slice(-2);
  var min = ("0" + inputDate.getMinutes()).slice(-2);
  var sec = ("0" + inputDate.getSeconds()).slice(-2);
  var dayIndex = inputDate.getDay();
  var monthNames = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
  var dayNames = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
  var result = "";

  switch(pattern) {
    case "YYYY-MM-DD":
      result = yr + "-" + mon + "-" + day;
      break;
    case "YYYY-MMM-DD DDD":
      result = yr + "-" + monthNames[parseInt(mon) - 1] + "-" + day + " " + dayNames[parseInt(dayIndex)];
      break;
  }

  return result;
}

var dateInput = input.VIP_2bParsed;
var formatPattern = "YYYY-MMM-DD DDD";
var formattedResult = formatDateTime(dateInput, formatPattern);

output = {formattedResult: formattedResult};

What could be causing this issue in Zapier specifically? Do I need to convert the input to a Date object first?

This happens because Zapier sends date values as ISO strings or timestamps, not actual Date objects. I ran into the same issue last year building automation workflows. Your function expects a Date object but gets a string - that’s why getFullYear throws an error. Add validation before calling formatDateTime. Use instanceof Date to check if it’s already a Date object. If not, convert it with new Date(dateInput). Watch out for invalid date strings though - they’ll create an Invalid Date object that still won’t work. Add if (isNaN(dateInput.getTime())) after conversion to catch cases where Zapier sends broken date data.

Had this exact problem with Zapier and third-party APIs. Zapier’s data transformation between steps is the culprit - sometimes dates come through as Unix timestamps instead of ISO strings, which makes everything messy. I built a more robust date parser that handles multiple formats. Add a preprocessing step that detects the input type first. If it’s numeric (timestamp), use new Date(parseInt(dateInput)). For strings, new Date(dateInput) works fine. Watch out for timezone differences too - some Zapier integrations send dates in different timezone formats depending on your data source.

yeah, zapier sends dates as strings by default. just wrap it in new Date() like var dateInput = new Date(input.VIP_2bParsed); before calling the function. that’ll fix it!