Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » max. future date of SS_datetime??

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

Page: 1
Go to End
Author Topic: 1397 Views
  • fj
    Avatar
    Community Member
    7 Posts

    max. future date of SS_datetime?? Link to this post

    what is the maximum future date of an SS_Datetime field in a model??
    I try to set "9999-31-12 23:59:00" and "2099-31-12 23:59:00" via YAML fixture file but both values do not work.
    "2029-12-11 23:59:00" works fine. hmmm.
    thanks!

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: max. future date of SS_datetime?? Link to this post

    I try to set "9999-31-12 23:59:00" and "2099-31-12 23:59:00"
    There is no 31st month.

    The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
    http://dev.mysql.com/doc/refman/5.1/en/datetime.html

  • fj
    Avatar
    Community Member
    7 Posts

    Re: max. future date of SS_datetime?? Link to this post

    Sorry, wrote it down the wrong way.

    now, I try to set "2039-12-31 23:59:00" but that does not work. I guess it's some 32bit unix timestamp issue. Could the default SS date parser be an issue here?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: max. future date of SS_datetime?? Link to this post

    I have no problem to save or parse that kind of date. Did you check your database and tried to insert the date via phpMyAdmin? May be it's a formatting issue with DateField.

  • fj
    Avatar
    Community Member
    7 Posts

    Re: max. future date of SS_datetime?? Link to this post

    OK, got it fixed. here is how:

    # when setting the date value to an SS_Datetime field by string (like "2039-12-31 23:59:00") the setValue method of SS_Datetime converts this string into a unix timestamp using strtotime. That timestamp is used to create a formatted string ('Y-m-d H:i:s') representing the date. but the timestamp seems to have some limitation (see http://www.tareeinternet.com/forum/knowledgebase/53-detailed-timestamp-information-tutorial.html)

    # so I extended the SS_Datetime class and overwrote the setValue() method. This allows me to use the php DateTime class (since php 5.2) to create the formatted string ('Y-m-d H:i:s') and set the objects value directly.

    # now I use the extended "eXSS_Datetime" classes in my models

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