code: function toDateTime(input, format) {
    format = format || "MM/DD/YYYY HH:mm:ss a";
    input = moment(input, format, true);
  
    if (input.isValid()) {
      return input.toDate();
    }
    else {
      return null;
    }
  }
docs: To datetime