Jump to:

21302 Posts in 5736 Topics by 2603 members

General Questions

SilverStripe Forums » General Questions » DateTimeField, Invalid time format

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

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 3638 Views
  • Mo
    Avatar
    Community Member
    465 Posts

    DateTimeField, Invalid time format Link to this post

    Hi All,

    I have been having a lot of issues with the datetimefield in 2.4. Basically, the popup calendar seems to enter the date in the wrong format (IE: DD/MM/YYYY, rather than MM/DD/YYY).

    Is there a way of configuring the format that silverstripe expects for this field? Or is this a Bug?

    Cheers,

    Mo

  • Anonymous user
    Avatar
    Community Member
    1 Post

    Re: DateTimeField, Invalid time format Link to this post

    This isn't that well documented, it's true..
    Here's an example of how to do it for NZDT, you'll want to adjust the format and locale for you own needs:

    $datefield = new DatetimeField('When', 'Date and time of event');
    $datefield->getDateField()->setConfig('showcalendar', true);
    $datefield->getTimeField()->setConfig('showdropdown', true);
    $datefield->getDateField()->setConfig('dateformat', 'dd/MM/YYYY');

    also, in mysite/_config.php, it's good to set your locale.

    i18n::set_locale('en_NZ');

    Cheers,
    - Luke

  • Mo
    Avatar
    Community Member
    465 Posts

    Re: DateTimeField, Invalid time format Link to this post

    Cool, that seems to work. Thanks Luke!

    Quick question, do you know if its possible to set $dateField->getDateField()->setConfig('dateformat', 'dd/MM/YYYY'); as the default for all versions of DateTimeField?

    Maybe overriding a static in the class?

    Cheers,

    Mo

  • Anonymous user
    Avatar
    Community Member
    1 Post

    Re: DateTimeField, Invalid time format Link to this post

    At the moment, I don't believe there's a direct way to do this, short of modifying the DateField code.
    The dateformat should be chosen by selecting the default for your locale. (from: i18n::get_locale()).

    You could always subclass DatetimeField and put in a setConfig call in your constructor.

    Cheers,
    - Luke

  • Dynamic
    Avatar
    Community Member
    16 Posts

    Re: DateTimeField, Invalid time format Link to this post

    Is it possible to do something like this with CalendarDateField? I'm digging through the sapphire folder to see what methods are available for DateField, but can't find anything like setConfig().

    Thanks!

  • Anonymous user
    Avatar
    Community Member
    1 Post

    Re: DateTimeField, Invalid time format Link to this post

    The CalendarDateField is now marked as obsolete in SilverStripe core. You can still use it by including the legacydatetimefields module, but the new core Date/Time fields all have this extra setConfig method.

    I believe that the legacy CalendarDateField will always use 'dd/MM/YYYY', and can't easily be configured, but I'm not sure that's correct, please reply here if you find more information on this.

    Cheers,
    - Luke

  • Ingo
    Avatar
    Forum Moderator
    787 Posts

    Re: DateTimeField, Invalid time format Link to this post

    I've opened a ticket for this here: http://open.silverstripe.org/ticket/5397

    Basically, we need to configure the javascript calendar library according to the date format settings in PHP.
    Unfortunately Zend_Date doesnt allow a more "forgiving" validation for date strings, so we have to ensure the js passes in the right format. I agree that "5 May 2010" is a bit of a weird default, thats the Unicode "date medium" setting for en_US...

    The date/time format confusion will also be less common once we implement this guy here: http://open.silverstripe.org/ticket/5352

    Suggestions welcome, its a tricky problem...

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: DateTimeField, Invalid time format Link to this post

    I ended up using DatePickerField from dataobjectmanager and modified a line of code to change that datepicker to US -style dates.

    3638 Views
Page: 1 2
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.