Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 551313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:22:49+00:00 2026-05-13T11:22:49+00:00

I have a problem with saving a date in my MySQL database. To test

  • 0

I have a problem with saving a date in my MySQL database.
To test everything:

I am trying to save 2010-01-01 (for example) in a MySQL database.
First I set my MySQL field to date. This didn’t work. But when I set the field to a string type it does save date in the database.

Why doesn’t it work when I want to save a date into a date field?

Although I think code isn’t important here I will post it since it’s requested.

I use zf 1.9.6

class JS_Form_EventForm extends ZendX_JQuery_Form{

    public function init($options=null){
        //parent::__construct($options);

        $this->setName("newEvent");
        $this->addElementPrefixPath('JS_Validate','JS/Validate/','validate');       
        //naam
        $evtName = new Zend_Form_Element_Text("evt_name");
        $evtName->setLabel("Evenement Naam: ")
                ->setRequired(true);
        // omschrijving
        $evtDescription = new Zend_Form_Element_Textarea("evt_description",array("rows"=>6,"cols"=>25));
        $evtDescription->setLabel("Evenement omschrijving: ");

        // locatie
        $evtAdr = new Zend_Form_Element_Select("adr_id");
        $evtAdr->setLabel("Locatie: ");
        $locaties = $this->getLocations();
        $evtAdr->setMultiOptions($locaties);

        $newAdr = new Zend_Form_Element_Button("new_adr");
        $newAdr->setLabel("+");
        // begin datum  
        $evtStartDate = new ZendX_JQuery_Form_Element_DatePicker("evt_startdate",array("label"=> "Begin Datum"));
        $evtStartDate->setJQueryParam('dateFormat', 'dd-mm-yy');
        $evtStartDate->addValidator(new Zend_Validate_Date('dd-mm-YYYY'));

        // eind datum
        $evtEndDate = new ZendX_JQuery_Form_Element_DatePicker("evt_enddate",array("label"=> "Eind Datum"));
        $evtEndDate->setJQueryParam('dateFormat', 'dd-mm-yy');
        $evtEndDate->addValidator(new Zend_Validate_Date('dd-mm-YYYY'));
        $evtEndDate->addValidator('CompareDates',false,array('evt_startdate'));

        // begin tijd
        $evtStartTime = new Zend_Form_Element_Text("evt_starttime");
        $evtStartTime->setLabel("Begin Tijd");
        $evtStartTime->addValidator(new Zend_Validate_Date('hh:mm',new Zend_Locale('auto')));

        // eind tijd
        $evtEndTime = new Zend_Form_Element_Text("evt_endtime");
        $evtEndTime->setLabel("Eind tijd");
        $evtEndTime->addValidator(new Zend_Validate_Date('hh:mm'));
        // aantal personen
        $amountPersons = new Zend_Form_Element_Text("evt_amtpersons");
        $amountPersons->setLabel("Aantal personen nodig ");

        $save = new Zend_Form_Element_Submit("save");
        $save->setLabel("Opslaan");


        $this->addElements(array($evtName,$evtDescription,$evtAdr,$newAdr,$evtStartDate,$evtEndDate,$evtStartTime,$evtEndTime,$amountPersons,$save));
        $this->setMethod('post');
        $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl().'/events/add');


    }

Saving the data:

 public function addAction()
    {
        // action body
                $form = new JS_Form_EventForm();
                if(!$this->getRequest()->isPost()){
                    $this->view->form = $form;
                }else{
                    $formdata = $this->_request->getPost();
                    if(!$form->isValid($formdata)){
                        $this->view->form = $form;
                    }else{

                        //http://zendgeek.blogspot.com/2009/07/zend-framework-building-complete.html
                        unset($formdata['save']);
                        $formdata['evt_name'] = ucfirst($formdata['evt_name']);
                        $e = new JS_Model_events();
                        $e->insert($formdata);
                        if($e ==true){

                            $this->_redirect('events/list');
                        }else{

                            echo 'Iets gaat niet goed';
                        }
                        /*
                        $formdata['sts_id'] = 1;
                        $eventsTable = new JS_Model_DbTable_events();
                        $eventsTable->insert($formdata);
                        */
                        die();
                        // form valid process data
                    }
                }
    }

class JS_Model_DBTable_Events extends Zend_Db_Table_Abstract{

    protected $_name = 'events';

    public function remove($id){
        if(isset($id)){
            $where = $this->getAdapter()->quoteInto('evt_id = ?', $id);
            return($this->delete($where));
        }else{
            return false;
        }
    }

    /*
     * function selectOne
     * @param int id the id of the event to select
     * @return resultset.
     */
    public function selectOneRow($id){

        //$where = $this->getAdapter()->quoteInto('evt_id = ?', $id);
        //$query = $this->select($where);
        //$result= $this->fetchRow($query);

        $select = $this->select();
        $select->where('evt_id = ?', $id);
        $rows = $this->fetchAll($select);

        return($rows);

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:22:50+00:00Added an answer on May 13, 2026 at 11:22 am

    I would guess this is the cause of your problem:

    $evtStartDate->addValidator(new Zend_Validate_Date('dd-mm-YYYY'));
    

    MySQL doesn’t understand date literals in the format dd-mm-YYYY. MySQL understands YYYY-MM-DD or YY-MM-DD, and a few other variations.

    See http://dev.mysql.com/doc/refman/5.1/en/datetime.html for official documentation on accepted date literal formats.


    Re comment: You can either convert the date in your PHP code, or else you can insert an expressing using the STR_TO_DATE() MySQL function. Pass a Zend_Db_Expr object in place of the literal value.

    $startdate_expr = $this->getAdapter()->quoteInto("STR_TO_DATE(?, '%d-%m-%Y')",
      $formdata["evt_startdate"]);
    $formdata["evt_startdate"] = new Zend_Db_Expr($startdate_expr);
    
    $enddate_expr = $this->getAdapter()->quoteInto("STR_TO_DATE(?, '%d-%m-%Y')",
      $formdata["evt_enddate"]);
    $formdata["evt_enddate"] = new Zend_Db_Expr($enddate_expr);
    
    $e->insert($formdata);
    

    Or you can change your web application’s form to require dates to be in YYYY-MM-DD format, and then you don’t have to convert anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem with saving a date into a MySQL database. I have
I am using CakePHP framework with MySQL database and I have problem in saving
Hi I have a problem saving 2 tables of my database at the same
I have a problem with saving the path in doctrine from a file upload.
I have problem for bulk insert of the file.I am saving the multiple record
I have errors when trying to commit saying transaction is out of date... but
I have two different columns to store date And time. One is saving date
I'm stuck with a problem around parsing date and time: I'm trying to parse
I have the following problem using Joda-Time for parsing and producing date and time
I have a text field for documentation, which is working good. Now the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.