Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Date::setValue()


Go to End


2111 Views

Avatar
xmedeko

Community Member, 94 Posts

23 July 2007 at 11:30am

Edited: 23/07/2007 11:40am

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.