mikefarah/yq · error
could not parse datetime of [%v] using layout [%v]: %w
Error message
could not parse datetime of [%v] using layout [%v]: %w
What it means
Inside the tz operator's per-node loop, parseDateTime could not interpret the node's scalar value using the currently active datetime layout (context.GetDateTimeLayout()). The value being converted and the layout are both printed; either the value is not a datetime at all or it uses a format that does not match the configured layout.
Source
Thrown at pkg/yqlib/operator_datetime.go:117
timezoneStr, err := getStringParameter("timezone", d, context, expressionNode.RHS)
layout := context.GetDateTimeLayout()
if err != nil {
return Context{}, err
}
var results = list.New()
timezone, err := time.LoadLocation(timezoneStr)
if err != nil {
return Context{}, fmt.Errorf("could not load tz [%v]: %w", timezoneStr, err)
}
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
parsedTime, err := parseDateTime(layout, candidate.Value)
if err != nil {
return Context{}, fmt.Errorf("could not parse datetime of [%v] using layout [%v]: %w", candidate.GetNicePath(), layout, err)
}
tzTime := parsedTime.In(timezone)
results.PushBack(candidate.CreateReplacement(ScalarNode, candidate.Tag, tzTime.Format(layout)))
}
return context.ChildContext(results), nil
}
func parseUnixTime(unixTime string) (time.Time, error) {
seconds, err := strconv.ParseFloat(unixTime, 64)
if err != nil {
return time.Now(), err
}
return time.UnixMilli(int64(seconds * 1000)), nil
}View on GitHub (pinned to 8b5af0694b)
Solutions
- Set the matching layout first, e.g. --datetime-format / with_datetime_format before tz
- Ensure the node values really are datetimes (filter or select them first)
- Fix malformed datetime strings in the source data
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/yqlib/operator_datetime.go:117 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05).
Data as JSON: /api/errors/ad8729bf441d8583.
Report an issue: GitHub.