Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

[solved] DateFormat in HasOneComplexTableField


Reply

11 Posts   1614 Views

Avatar
Devlin

18 August 2011 at 2:35am (Last edited: 18 August 2011 2:38am), Community Member, 215 Posts

Hi there. Just add the following code to your HasOneComplexTableField.

$tablefield = new HasOneComplexTableField();
$tablefield->fieldCasting = array(
'Date' => array("Date->Format","d-m-Y"),
);

You can use array("Date->FormatI18N","%d. %B %Y") for a even nicer date too.

http://api.silverstripe.org/2.4/forms/fields-relational/ComplexTableField.html
http://api.silverstripe.org/2.4/sapphire/model/Date.html#methodFormat
http://api.silverstripe.org/2.4/sapphire/model/Date.html#methodFormatI18N

Avatar
quanto

18 August 2011 at 2:42am Community Member, 81 Posts

Thanks Devlin (and martimiz), It works!

Avatar
martimiz

18 August 2011 at 3:12am Forum Moderator, 1091 Posts

@Devlin - nice!