The docs for dateformat omit something essential; the string that specifies the format has to refer to the second of january in the year 2006.
A quick search on dateformat on this discourse shows that I am not the only one who bumped into this issue, which is very frustrating because no error is given, even if the dateformat output gives nonsensical results such as it being the year 9000.
Please modify the page to say this.
P.S. Does anyone know how the dateformat function disambiguates the 2 in the year from the 2 which is the day? Is it just not possible to have a date formatted as
[day] [month] '[year] millenium 2 century 0 or similar?