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 959199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:59:12+00:00 2026-05-16T00:59:12+00:00

I want to be able to get and set the date using my own

  • 0

I want to be able to get and set the date using my own date format (dd/mm/yyyy) and not doctrine (yyyy-mm-dd). I’ve found a way that is specifying a getter and setter for every date field however I want do it in a more convenient way (1 setter + 1 getter for every date field in every table is a lot)

class Curs extends BaseCurs {
    private function fechaDesdeEsp($fecha){
        $fecha = new DateTime($fecha);
        return $fecha->format('Y-m-d');
    }
    private function fechaDesdeIso($fecha){
        $fecha = new DateTime($fecha);
        return $fecha->format('d/m/Y');
    }
    public function setFechainici($fecha_inici) {
        return $this->_set('fecha_inici', $this->fechaDesdeEsp($fecha_inici));
    }
    public function getFechainici() {
        return $this->fechaDesdeIso($this->_get('fecha_inici'));
    }

}

Hope you find a solution, Thanks in Advance

  • 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-16T00:59:13+00:00Added an answer on May 16, 2026 at 12:59 am

    I’ve found this to be the best solution for me:

    /// models/DateFormatBehaior.php
    class DateFormatListener extends Doctrine_Record_Listener{
    
        public function preInsert(Doctrine_event $Event){
            $this->_prepare_date($Event);
        }
    
        public function preUpdate(Doctrine_event $Event){
            $this->_prepare_date($Event);
        }
    
        // Private stuff
        private function _prepare_date(Doctrine_event $Event){
            $Model = $Event->getInvoker();
            foreach($Model->getTable()->getColumns() as $FieldName=>$Field){
                if($Field['type']=='timestamp'){
                    if(preg_match("/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/",$Model[$FieldName],$Matches)){
                        $Model->$FieldName = sprintf("%s-%s-%s 00:00:00",$Matches[3],$Matches[2],$Matches[1]); // YYYY-DD-MM HH:MM:SS
                    }
                }
            }
        }
    
    }
    class DateFormatTemplate extends Doctrine_Template{
    
        public function setTableDefinition(){
    
            $this->addListener(new DateFormatListener);
        }
    
    }
    

    Then, each model who has timestamp fields:

    /// models/MyModel.php
    abstract class MyModel extends Doctrine_Record{
    
        public function setTableDefinition(){
            // [...]
        }
         public function setUp(){
            parent::setUp();
            $this->actAs("DateFormatTemplate");
            // [...]
         }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 50+ kiosk style computers that I want to be able to get
I want to get week Start Date of a week. I am able to
I want to be able to get the next and previous row using SQLite.
I want to be able to shift time if a $_GET['date'] is set. Here
I want to be able to get an estimate of how much code &
I want to be able to get an estimate of how much code &
I want to be able to get the projects I have in Sourcesafe and
I want to be able to get the current bound object in the ItemTemplate
I want to be able to get different array values in my ajax callback
I want to be able to get something similar to this.. I want to

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.