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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Date in DOM interface


Go to End


3 Posts   1443 Views

Avatar
barryvanveen

Community Member, 11 Posts

23 July 2010 at 5:03am

Hey all,

I've added a datefield to one of my DOM classes and added some configuration:

class NotulenItem extends DataObject {

    static $db = array(
        'Vergaderdatum' => 'Date'
    );

    function getCMSFields_forPopup() {
        $dateField = new DateField('Vergaderdatum');
        $dateField->setConfig('showcalendar', true);
        $dateField->setConfig('dateformat', 'dd/MM/YYYY');
        $dateField->setLocale('nl_NL');

        $fields = new FieldSet();
        $fields->push($dateField);
        return $fields;
    }

}

This works just about right, when I add a record to my page I see the date in the format I want (dd-mm-yyyy). When I then return to the overview of records that are attached to the page, the date is shown in the default format (yyyy-mm-dd). Is there some way I can influence the format of the Date in the DOM overview?

Cheers!

Barry

Avatar
UncleCheese

Forum Moderator, 4102 Posts

23 July 2010 at 5:20am

Yup.. just write a custom getter..

public function getNiceDate() {
return $this->obj('YourDatefield')->Format('d-m-Y');
}

and then in your fields array, just use "NiceDate" in place of the native date field in the DB.

Avatar
barryvanveen

Community Member, 11 Posts

23 July 2010 at 6:34am

Thank you very much for the fast reply, works like a charm :-)