Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » I need CMS DateField to only show date, not time.

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

Page: 1
Go to End
Author Topic: 997 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    I need CMS DateField to only show date, not time. Link to this post

    If I have a $db 'Date' => 'Date' and then in getCMSFields() I have new DateField('Date'), it shows the date and time. I want it to only show the date because there is no time needed.

    Note: I just noticed that the Database field type was datetime so I changed it to date and that fixed the issue.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: I need CMS DateField to only show date, not time. Link to this post

    But still sometimes you want to store date in datetime format, but in one situation only display them in DD-MM-YYYY and in another situation in DD-MM-YYYY HH:MM.

    I couldn't find any SS build in solution, so I think creating a method in your controller will fix the issue:

    function Nicedate(){
       $datetime = new DateTime($this->YourDateTimeField); // >= php 5.2
       return $datetime->format('jS, F Y'); // or d-m-Y
    }

    997 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.