We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to save the date in oracle?

I need to keep the date oracle and I think the developer tools, saved the date in mm-dd-yyy. While Oracle saved the date in dd / mm / yyyy as change the date format of the input element. How to save the date in oracle?

You can define a beforeSave function in your model to format the date as you need.



81.1k

Something like this or what would be the best way to validate the format

public function beforeSave()
{
    // Set the modification date
    $this->modified_in = date('Y-m-d H:i:s');
}

Yes that's the way to validate data and more with validators :
https://docs.phalcon.io/en/latest/reference/models.html



81.1k

public function afterFetch() { $this->start = new DateTime($this->start); }

  public function beforeSave()
  {
      $this->start = $this->start->format("Y-m-d H:i:s");
  }
edited Feb '16

That should work, or you can use Phalcon\Mvc\Model\Behavior\Timestampable :

public function initialize()
{
    $this->addBehavior(new Timestampable([
        'beforeSave'  => [
            'field'     => 'start',
            'format'    => 'Y-m-d H:i:s'
        ]
    ]));
}


2.5k
Accepted
answer

Use new \Phalcon\Db\RawValue('SYSDATE');