cakephp datetime insertion behaviour
Posted
by
littlechad
on Stack Overflow
See other posts from Stack Overflow
or by littlechad
Published on 2011-02-13T15:14:08Z
Indexed on
2011/02/13
15:25 UTC
Read the original article
Hit count: 216
hi everyone
this is a cakePHP question about datetime database insertion mismatch, i jumped in to this project while the whole thing is already built around 70%.
here's what happen, every time i insert a data that contain a datetime, the inserted time doesn't match the inputted date, and the mismatch has no pattern or what ever, in some table the differences is 5 hours, while in others it could be 12 hours, 7 hours, or even 15 hours.
i have traced this by investigating the controller, the model, the app_controller, everything but i don't find anything that indicate a datetime insertion rules.
if the view :
echo $form->input('start_date', array('label' => __l('start date'));
i can't even find in the controller anything like:
$this->data['current_controller']['start_date'] = $this->data['current_controller']['start_date'];
when i use pr($this->data); to print the posted data, this is shown:
[start_date] => Array
(
[month] => 02
[day] => 16
[year] => 2011
[hour] =>
[min] =>
[meridian] =>
)
so i figured doing something like:
$yearMonDay = $this->data['current_controller']['start_date']['year']."-";
$yearMonDay .= $this->data['current_controller']['start_date']['month']."-";
$yearMonDay .= $this->data['current_controller']['start_date']['day'];
if(!empty($this->data['current_controller']['start_date']['hour'])){
$hourMinSec = $this->data['current_controller']['start_date']['hour'].":";
$hourMinSec .= $this->data['current_controller']['start_date']['min'].":";
$hourMinSec .= $this->data['current_controller']['start_date']['meridian'];
}else{
$hourMinSec = "00:00:00";
}
$this->data['Deal']['start_date'] = $yearMonDay." ".$hourMinSec;
just to make sure
the funny thing is that those posted datetime is inserted into the database with the mismatch value anyway. it's getting pretty frustrating, is there any suggestion on where else should i find the codes that define how the datetime should be inserted? or probably give me a clue on how to override those mismatched insertion rules?
thanks
© Stack Overflow or respective owner