I'm trying to save data in a table but when i save it throws the below error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1540564519' for column 'date_updated' at row 1 On saving model evaluation_remedy
evaluation_remedy Table Schema:
--
-- Table structure for table `evaluation_remedy`
--
CREATE TABLE IF NOT EXISTS `evaluation_remedy` (
`id` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`diet` text NOT NULL,
`is_local_food_store` tinyint(4) NOT NULL DEFAULT '0',
`product_image` varchar(255) DEFAULT NULL,
`product_description` text,
`product_url` varchar(255) DEFAULT NULL,
`importance` tinyint(4) NOT NULL DEFAULT '0',
`is_active` tinyint(4) NOT NULL DEFAULT '1',
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8;
--
-- Indexes for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `evaluation_remedy`
--
ALTER TABLE `evaluation_remedy`
MODIFY `id` int(10) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=64;
Let me know if any other information is required. I will be happy to share anything required for the solution.
Store/Save Function:
public function saveEvaluationRemedyAction(){
// Instantiate new form for Evaluation Symptom Model
$form = new EbEvaluationRemedyForm();
if( $form ->isValid($this->request->getPost())){
// Get the Evaluation Symptom id (if any)
$id = $this->request->get( 'id', null );
// Get existing Evaluation Symptom (if any) or create a new one
if( null !== $id && $id !== '' ){
$evaluationRemedy = CxEbEvaluationRemedy::findFirst( $id );
} else {
$evaluationRemedy = new CxEbEvaluationRemedy();
}
// Bind form with post data
$form->bind( $this->request->getPost(), $evaluationRemedy );
// Save the form with new data
$evaluationRemedy->save();
// Saving linked remedies in Related Remedy Table
$remedies = $this->request->get('remedies_list');
if($remedies){
foreach ($remedies as $key => $remedy) {
$relatedRemedy = CxEbEvaluationRemedy::getIdByName($remedy);
$remedyObject = new CxEbEvaluationRemedyRelated();
$remedyObject->setEvaluationRemedyId($evaluationRemedy->getId());
$remedyObject->setEvaluationRelatedRemedyId($relatedRemedy['id']);
$remedyObject->save();
}
}
} else {
// Send error Json response
return CxHelper::SendJsonError($form->getHtmlFormattedErrors());
}
// Return success
return array( 'data' => 'Success' );
}
Let me know if any other information is required. I will be happy to share anything required for the solution.
Thanks
Convert it from Epoch Time like this:
<?php
$date = new DateTime('@1540564519');
$formatted = $date->format('Y-m-d H:i:s');
echo $formatted; // 2018-10-26 14:35:19
See it here https://3v4l.org/8jgUp