How do I remove x characters from a string?

I have variables/strings in the following format with the variable name Zeitraum_Begin


I want to remove the last six characters to show only the year.


I use {{ .Zeitraum_Begin | truncate 4 }}

But it put out 2019 … which is correct.

Is there a filter to remove x characters from a string? I haven’t found a filter for that.

If you store them in your data files/front matter without quotes, you could use date formatting to get to where you want.

If it’s a string, see

Hey @bep thank you for your answer! So there is no truncate version without the …, right?

I will try the date-version. Thank you for the link!

It would be a good idea to link the page on › That’s where I searched first for a similiar function!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.