{"record":{"id":"99649b0dd59e6cb7","repo":"OrchardCMS/OrchardCore","slug":"could-not-parse-date","errorCode":null,"errorMessage":"Could not parse date","messagePattern":"Could not parse date","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/DateTimeParser.cs","lineNumber":221,"sourceCode":"                {\n                    var success = true;\n                    if (!DateTime.TryParse(dateValue, context.CultureInfo, DateTimeStyles.None, out var dateTime))\n                    {\n                        if (!DateTime.TryParse(dateValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))\n                        {\n                            success = false;\n                        }\n                    }\n\n                    // If no timezone is specified, assume local using the configured timezone.\n                    if (success)\n                    {\n                        var converted = context.Clock.ConvertToTimeZone(dateTime, context.UserTimeZone);\n                        return new DateNode2(converted.UtcDateTime.Date);\n                    }\n                }\n\n                throw new ParseException(\"Could not parse date\", context.Scanner.Cursor.Position);\n            });\n\n        var currentParser = OneOf(nowParser, todayParser);\n\n        var valueParser = OneOf(currentParser, dateParser);\n\n        var rangeParser = valueParser\n            .And(ZeroOrOne(range.SkipAnd(OneOf(currentParser, dateParser))))\n            .Then<ExpressionNode>(x =>\n            {\n                if (x.Item2 == null)\n                {\n                    return new UnaryExpressionNode(x.Item1);\n                }\n\n                else\n                {\n                    return new BinaryExpressionNode(x.Item1, x.Item2);","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/DateTimeParser.cs#L203-L239","documentation":"DateTimeParser is the Liquid/template date parser used by AuditTrail query helpers. It throws ParseException when the input string matches none of the registered parsers (now, today, or explicit date formats). The library throws this because after exhausting all alternative grammar rules there is no valid parse left at the current cursor position.","triggerScenarios":"Calling a template/query filter that parses a date string (e.g. filtering audit trail events by date) with a value that is neither 'now', 'today', nor a recognized date format such as 'yyyy-MM-dd'. Any typo, extra whitespace pattern, or locale-formatted date falls through to this exception.","commonSituations":"Users typing dates like '01/02/2024' in a locale the parser does not accept, passing 'yesterday' or other relative keywords that are not implemented, or query string values copied with trailing characters.","solutions":["Use one of the supported literal values: 'now' or 'today'.","Format the date in the parser's expected format (e.g. ISO 'yyyy-MM-dd').","Pre-validate the input with DateTime.TryParse (with the correct culture) before passing it to the parser.","If you need additional formats or relative dates, extend the parser grammar rather than post-processing the exception."],"exampleFix":"// before\nvar filter = \"yesterday\"; // throws ParseException\n// after\nvar filter = DateTime.Today.AddDays(-1).ToString(\"yyyy-MM-dd\");","handlingStrategy":"validation","validationCode":"var known = new[] { \"now\", \"today\" };\nbool ok = known.Contains(input, StringComparer.OrdinalIgnoreCase) || DateTime.TryParseExact(input, \"yyyy-MM-dd\", CultureInfo.InvariantCulture, DateTimeStyles.None, out _);\nif (!ok) throw new FormatException($\"Unsupported date expression: {input}\");","typeGuard":"static bool IsParsableDate(string? s) => s is not null && (s.Equals(\"now\", StringComparison.OrdinalIgnoreCase) || s.Equals(\"today\", StringComparison.OrdinalIgnoreCase) || DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.None, out _));","tryCatchPattern":"try { node = parser.Parse(input); }\ncatch (ParseException ex) { logger.LogWarning(ex, \"Bad date input: {Input}\", input); return Results.BadRequest(new { error = \"Invalid date format\" }); }","preventionTips":["Stick to 'now', 'today', or ISO yyyy-MM-dd inputs","Normalize user locale dates to ISO before parsing","Add form-level date validation in the UI","Unit-test the parser with every format your UI can emit"],"tags":["date-parsing","audittrail","template"],"backgroundTag":"invalid-date-format","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}