Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Date::setValue()

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1583 Views
  • xmedeko
    Avatar
    Community Member
    94 Posts

    Date::setValue() Link to this post

    Hi,
    the setValue() method in Date class is
    [code php]
    function setValue($value) {
    if( is_array( $value ) && $value['Day'] && $value['Month'] && $value['Year'] ) {
    $this->value = $value['Year'] . '-' . $value['Month'] . '-' . $value['Day'];
    return;
    }

    // Default to NZ date format - strtotime expects a US date
    if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts))
    $value = "$parts[2]/$parts[1]/$parts[3]";

    if($value) $this->value = date('Y-m-d', strtotime($value));
    else $value = null;
    }

    But the lines
    [code php]
    // Default to NZ date format - strtotime expects a US date
    if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts))
    $value = "$parts[2]/$parts[1]/$parts[3]";

    do not work, because of the code
    [code php]
    if($value) $this->value = date('Y-m-d', strtotime($value));

    So, if I set the date to '23/07/2007', then the date in DB is 0000-00-00.

    P.S. Also the first condition in DateField::setValue() looks weird.

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