{"record":{"id":"12390d4d24c47e32","repo":"kestra-io/kestra","slug":"the-dayofmonth-function-could-not-parse-date","errorCode":null,"errorMessage":"The 'dayOfMonth()' function could not parse 'date': {e.getMessage()}","messagePattern":"The 'dayOfMonth\\(\\)' function could not parse 'date': (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/DayOfMonthFunction.java","lineNumber":38,"sourceCode":" *\n * @param date any valid ISO 8601 date or datetime string\n */\npublic class DayOfMonthFunction implements KestraFunction {\n    public static final String NAME = \"dayOfMonth\";\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        Object dateArg = args.get(\"date\");\n\n        if (dateArg == null) {\n            throw new PebbleException(null, \"The 'dayOfMonth()' function expects a 'date' argument.\", lineNumber, self.getName());\n        }\n\n        LocalDate localDate;\n        try {\n            localDate = DateUtils.parseLocalDate(dateArg.toString());\n        } catch (InternalException e) {\n            throw new PebbleException(e, \"The 'dayOfMonth()' function could not parse 'date': \" + e.getMessage(), lineNumber, self.getName());\n        }\n\n        return localDate.getDayOfMonth();\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"date\");\n    }\n\n    @Override\n    // HashMap is required here because Map.of() does not allow null values,\n    // and null defaults indicate arguments with no meaningful autocompletion default.\n    public Map<String, String> getArgumentDefaults() {\n        HashMap<String, String> defaults = new HashMap<>();\n        defaults.put(\"date\", null);\n        return defaults;\n    }","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/DayOfMonthFunction.java#L20-L56","documentation":"dayOfMonth() delegates parsing to DateUtils.parseLocalDate and wraps any InternalException as a PebbleException. The error means the 'date' argument was present but not parseable as an ISO 8601 date/datetime (e.g. '15/01/2024', 'Jan 15', or a non-date string).","triggerScenarios":"Passing a locale-specific format like {{ dayOfMonth('15-01-2024') }}, a relative word like 'today', or a value that is a string but not a date (e.g. an id).","commonSituations":"Upstream system emitting non-ISO dates; user-entered dates in DD/MM/YYYY; binding date to the wrong output field.","solutions":["Pass an ISO 8601 value: 'yyyy-MM-dd' or 'yyyy-MM-dd'T'HH:mm:ss'.","Reformat the upstream date to ISO before calling dayOfMonth using a script/output transformation.","Validate the format before use and fall back to a known good date."],"exampleFix":"// before\n{{ dayOfMonth('15/01/2024') }}\n// after\n{{ dayOfMonth('2024-01-15') }}","handlingStrategy":"validation","validationCode":"// Pebble: normalize to ISO before calling dayOfMonth\n{{ dayOfMonth(date=myDate | date(format=\"yyyy-MM-dd\")) }}  // if a date filter is available; otherwise reformat upstream","typeGuard":"// Java: ISO 8601 date pattern check\nString iso = \"^\\\\d{4}-\\\\d{2}-\\\\d{2}(T\\\\d{2}:\\\\d{2}(:\\\\d{2})?(\\\\.\\\\d+)?(Z|[+-]\\\\d{2}:\\\\d{2})?)?$\";\nif (!dateArg.toString().matches(iso)) throw new IllegalArgumentException(\"date is not ISO 8601\");","tryCatchPattern":null,"preventionTips":["Pass ISO 8601 dates only (yyyy-MM-dd or full datetime).","Reformat locale-specific dates upstream before calling dayOfMonth.","Bind date to a known date output field, not free text."],"tags":["pebble","function","date","parse","iso8601"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}