Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$Date.Format on Silverstripe 4 Template

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

like image 318
Denis Avatar asked Mar 26 '18 11:03

Denis


2 Answers

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')
like image 140
scrowler Avatar answered Sep 18 '22 09:09

scrowler


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

like image 27
Forkoff.co.uk Avatar answered Sep 20 '22 09:09

Forkoff.co.uk