phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

[NFR] Datetime column type #524

Closed SliceOfLife closed 6 years ago

SliceOfLife commented 11 years ago

What about adding "datetime" column type for Model? By default the "@var \Datetime" converted to string.

niden commented 11 years ago

@SliceOfLife I am not sure I understand what you mean. Could you please explain with an example what you are trying to do ?

SliceOfLife commented 11 years ago

For example, I have a Mysql DB and table with datetime column. I want to write the Model class with \DateTime field:

class SomeModel extends \Phalcon\Mvc\Model 
{
    /**
     * @Column(type="datetime", nullable=false)
     *
     * @var \DateTime
     */
    public $datetime_field;

    public function initialize()
    {
        $this->datetime_field = new \DateTime();
    }
}

But I can't use the "datetime" column type, it's very sad. This code throws error like "Object of class DateTime�����w could not be converted to string".

niden commented 11 years ago

Hmmm for some reason my comment disappeared.

Either way.

This is not a blocker and the desired functionality can be achieved with a minor change in the code. We can add it as a NFR but it will take a low priority one and we also need to test the impact that this will have on the framework as far as performance is concerned.

You can achieve what you need with:

$now = new \DateTime();
$this->datetime_field = $now->format('Y-m-d H:i:s');

or without using datetime

$this->datetime_field = date('Y-m-d H:i:s');
SliceOfLife commented 11 years ago

It will be a cool feature. By the way, I use an integer timestamp and Mysql INT(11) type for now.

niden commented 11 years ago

I follow the same practice too (using integers). Much faster to search/index, you can perform easy math operations with them (to find differences etc.) and for me at least it is a lot more logical. You also escape the different formatting conventions i.e. m/d/y, y.m.d etc.

niden commented 11 years ago

@dalu I haven't personally used a 32bit machine in a few years and are seeing them disappear. However, the easy solution on that would be again numeric fields. You will just need to have two per date (if you want to store hours/minutes/seconds)

For the date I would store this:

20130414 (which is 2013-04-14)

and for the time the same thing

175432 (which is 17:54:32)

This way you have no issues with 32 bit machines. :)

Having said that, with the way technology is going, I doubt we will have any 32bit machines by that year.

niden commented 11 years ago

Closing this as we will not be implementing automatic Datetime fields in Phalcon in the very near future. Perhaps in 2.0+

lfbittencourt commented 9 years ago

+1 for this!

tmihalik commented 9 years ago

+1

AndreBaumeier commented 9 years ago

+1

loopsframework commented 9 years ago

+1 I would welcome it if Phalcon translates the DateTime object to the format expected by the database backend. With this layer of abstraction, code should become more portable.

f3l1x commented 9 years ago

:+1:

sergeyklay commented 9 years ago

@niden

Closing this as we will not be implementing automatic Datetime fields in Phalcon in the very near future. Perhaps in 2.0+

Now is 2.0+ :)

MLukman commented 8 years ago

I vote for this feature implemented about now.

StudioMaX commented 8 years ago

+1

reloaded commented 7 years ago

+1

efimBistrov commented 7 years ago

+1

kornerita commented 7 years ago

Hi,

I've found this thread and I would like to add the following:

My personal opinion about this, is that an ORM should abstract you on the date format the database engine is using and should use native language date manipulations. This adds transparency when you want or need to change a database engine.

Regards, Federico.

stale[bot] commented 6 years ago

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

StudioMaX commented 6 years ago

This is still relevant.

niden commented 6 years ago

https://github.com/phalcon/cphalcon/pull/13562