Sunday, May 10, 2015

Re: How to set Cake 3.0 to save with different date format ?

i found this topic here and on Stack Overflow: https://stackoverflow.com/questions/29336852/how-to-format-date-fields-before-save-in-cakephp-3
The hash on the linked Doc page is no longer valid.

Like the original post, i don't want to use the default select-based date inputs. i'm formatting my date in US format for output ('m/d/Y') and using the 'mdy' Validator. i've also written a mutator in the Entity to convert the date string to a Time object:
protected function _setReadyDate($readyDate)
{
    $this
->_properties['ready_date'] = new Time($readyDate);
   
return $this->_properties['ready_date']->format('Y-m-d');
}

i added the lines from the Stack answer to my bootstrap.php, but that didn't work either:
I18n::locale('en-US');
Type::build('datetime')->useLocaleParser();

No matter what i do, the MySql UPDATE uses the 'm/d/Y' string instead of the date object:
UPDATE listings SET ready_date = '06/01/2015' , modified = '2015-05-11 05:00:54' WHERE id = 20

What do i try next?

Thanks,
joe t.






On Thursday, 2 April 2015 14:56:29 UTC-4, José Lorenzo wrote:
Read this:

http://book.cakephp.org/3.0/en/orm/database-basics.html#parsing-localized-datetime-data

On Thursday, April 2, 2015 at 6:10:58 PM UTC+2, Celso wrote:
Hi guys I have a table in Mysql with a date field,  and I need to allow my user writes something like 31/12/2015.


echo $this
->Form->input('data_nascimento', ['type' => 'text', 'maxlength'=> '10']);

I've tried
Time::$defaultLocale = 'pt-BR';

in AppController but the problem persists...
and 
'timezone' => 'BRT'
in app.php does not works

If I update the value directly in MySQL and use the
Time::setToStringFormat('dd/MM/YYYY');
in AppController the date is showed in a nice format however my real problem is how to save() because I don't know how change the locale of Cake 3.0.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: