Frage

Am using Yii Wheels Date Picker to pick dates and I tried to save dates to database via Yii ActiveRecord it worked fine. Now I want to store Unix time-stamp not the Date itself. I have tried all suggestion from PHP Date class, to strtotime with no sucess. Yii's CDateTimeParser::parse does not work too. Date inserted is always unix epoch so I know by that that my conversion does not work. my dates are in format 1972-03-02

I have run out of ideas.

here is my code:

    protected function beforeSave() 
    {
        if(parent::beforeSave()) 
        {         
            //change date to Unix time stamp 
            $this->ccalstartdate = CDateTimeParser::parse($this->ccalstartdate, 'yyyy-MM-dd');
            $this->ccalenddate = CDateTimeParser::parse($this->ccalenddate, 'yyyy-MM-dd'); 
        }
        return parent::beforeSave();
    }

EDIT After running in debugger I can see conversion goes right but the values are not saved to database correctly. So something else is the cause. Up until AR save is called, the attributes are correct. So I guess this method is not the cause at all.

War es hilfreich?

Lösung

I was fighting wrong battle. The code above works just fine. The problem was that I was using zii.widgets.CDetailView in my view widget to check the values. The widget was converting the thing and upon failing (was using its internal format) it printed that wrong number. I checked the database value and they are correctly stored as unix time stamps. Thanks for everyone that tried to help. Next time I have to be more careful!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top