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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Date::setValue()


Go to End


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