Jump to:

5452 Posts in 1673 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Admin displays date field year 1 year behind

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

Page: 1
Go to End
Author Topic: 573 Views
  • Media Contour
    Avatar
    Community Member
    33 Posts

    Admin displays date field year 1 year behind Link to this post

    I have a page type in the admin with a date field. When I enter a date in the admin for example September 8, 1994 it displays correctly in the front end but when i refresh the admin the date displays as Septemeber 8, 1993 one year behind. Any suggestions as to why this is happening?

    ArticlePage.php

    <?php

    class ArticlePage extends Page {
       static $db = array(
          'Date' => 'Date',
          'Time' => 'Time'
       );
       
       static $has_one = array('ArticleAuthor' => 'Author');
       
       static $has_many = array('ArticleImages' => 'ArticleImage');
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 12/12/2011)'), 'Content');
          $dateField->setConfig('showcalendar', true);
           $dateField->setConfig('dateformat', 'MM/dd/YYYY');
        $fields->addFieldToTab('Root.Content.Main', $timeField = new TimeField('Time','Article Time (for example: 00:00:00)'), 'Content');
           $timeField->setConfig('showdropdown', true);
          
          $articleimages = new ImageDataObjectManager(
             $this,
             'ArticleImages',
             'ArticleImage',
             'Image',
             array(
                'Name' => 'Name',
                'Caption' => 'Caption'
             ),
             'getCMSFields_forPopup'
          );
          $fields->addFieldToTab('Root.Content.ArticleImages', new LiteralField('Article Images Break', '<br />'));
          $fields->addFieldToTab('Root.Content.ArticleImages', new LabelField('Article Images Label', 'Article Images'));
          $fields->addFieldToTab('Root.Content.ArticleImages', $articleimages);
          
          $author = new HasOneDataObjectManager(
             $this,
             'ArticleAuthor',
             'Author',
             array(
                'FirstName' => 'FirstName',
                'MiddleName' => 'MiddleName',
                'LastName' => 'LastName',
                'Link' => 'Link'
             ),
             'getCMSFields_forPopup'
          );
          $fields->addFieldToTab('Root.Content.Author', new LiteralField('Article Author Break', '<br />'));
          $fields->addFieldToTab('Root.Content.Author', new LabelField('Article Author', 'Article Author'));
          $fields->addFieldToTab('Root.Content.Author', $author);
          
          return $fields;
       }
    }

    class ArticlePage_Controller extends Page_Controller {}

    ?>

  • Pipifix
    Avatar
    Community Member
    54 Posts

    Re: Admin displays date field year 1 year behind Link to this post

    Hello.

    I got the same strange behavior. Did you get this problem solved?

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: Admin displays date field year 1 year behind Link to this post

    I don't know if this is the same thing but I remember running into something like that once, where it helped using yyyy instead of YYYY. I can still reproduce it - but in my case only for the first of januari

    573 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.