HomeDocs › %G

Python strftime directive %G

ISO 8601 week-based year. Use with %V and %u, never with %Y.

Example (from datetime(2026, 6, 18, 13, 45, 30))
2026

In Python

from datetime import datetime
dt = datetime(2026, 6, 18, 13, 45, 30)
dt.strftime("%G")
# => "2026"

Parsing with strptime

Parses an ISO 8601 year; requires %V and %u to resolve a date. See strptime.dev for the parsing side.

Try %G in the live tester →

Other Year directives