I have a date in the database with this format "YY-mm-dd". On the template I want it in this format: dd.mm.YY Usually it would work with $date.Format('d.m.Y') But not in Silverstripe 4. It converts from 2018-05-08 to 8.0.2018. Only the year is correct. Was there a change. I didn't find anything in the Documentation
Asked
Active
Viewed 5,999 times
2 Answers
15
Date formats in SS4 were changed from PHP date formatting to CLDR date formatting (changelog link):
Changed Format() method to use CLDR format strings, rather than PHP format string. E.g. d/m/Y H:i:s (php format) should be replaced with to dd/MM/y HH:mm:ss (CLDR format).
You can use this to achieve what you want:
$Date.Format('dd.MM.y')

scrowler
- 24,273
- 9
- 60
- 92
-
5this makes me a n g e r e y – Isaac Oct 23 '18 at 03:25
-
4What's worse is that their so called "documentation" is silent on these issues. It "documents" the parameter as literally "the format string".... you don't say Sherlock... – Phoenix Jan 19 '19 at 23:01
-
Is there no way to change the default formatting in SS4 via config? That way we can retain backward compatibility more easily without having to revise every instance. – patricknelson Jun 20 '19 at 02:44
-
You’d need to replace a bunch of core classes, and third party modules would then break unless you built your adapter to handle both formats. Better to bite the bullet IMO – scrowler Jun 20 '19 at 06:13
-
Sometimes its really hard just to find basic documentation like this on simple formatting. – pinkp Oct 24 '19 at 18:24
2
The guide mentioned in the previous answer regarding date formatting has moved. The new location for CLDR date formatting as used by Silverstripe 4 can be found here: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table

Forkoff.co.uk
- 55
- 7
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/29805186) – no ai please Sep 13 '21 at 01:02