Reformat a date from getCSV data?

I have a csv file which looks like this:

“post/”,“Logan”,"",“Testing form.”,“2019-05-24T01:33:24.501Z”
“post/”,“Marcia”,"",“Testing a comment.”,“2019-05-24T00:55:04.800Z”

I use getCSV in single.html to check if the current filename matches “article” in the csv file. If it matches then “name”, “created_at”, and “message” are displayed from the csv.

{{ $FilePath := .File.Path }}
{{ $url := "csv/comment.csv" }}
{{ $sep := "," }}
{{ range $i, $r := getCSV $sep $url }}
{{ if eq (index $r 0) $FilePath }}
<p>{{ index $r 1 }} on {{ index $r 4 }}</p>
<p>{{ index $r 3 }}</p>
{{ end }}
{{ end }}

The problem I have is with displaying the date. The date is in the format 2019-05-24T00:55:04.800Z. The date is generated by Netlify on a form submission so that’s how it ends up in the csv in that format.

I am unable to convert it using dateFormat.

I have tried:

{{ dateFormat "Jan 2, 2006" {{ index $r 4 }} }}

but that gives the error:

Failed to add template “_default/single.html” in path “_default/single.html”: template: _default/single.html:32: unexpected “{” in operand

Is there a way to reformat this date? Or is it best to take another approach and pre-process the csv file before dropping it into Hugo?


You can’t nest {{}}s like that. Try instead with () .