Yii Framework Forum: Datepicker subtracts a day - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Datepicker subtracts a day while the database stores correct value

#1 User is offline   rmist 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-March 18

Posted 01 March 2018 - 07:24 AM

Hi, first post here,
I hope you guys can help me a little. I'm working on my first yii2 application and I just installed krajees datecontrol (im not allowed to link it right now)

And it's working. As a visitor, I can choose a date and it gets stored in the database (in unixtime).

Code:
$form->field($model, 'myDateField')->widget(DateControl::classname(), [
                        'type'=>DateControl::FORMAT_DATE,
                        'ajaxConversion'=>true,
                        'saveFormat' => 'php:U',
                        'displayFormat' => 'php:d.m.Y',
                        'saveTimezone' => 'Europe/Amsterdam',
                        'displayTimezone' => 'Europe/Amsterdam',
                        'language' => 'de',
                       
                        'widgetOptions' => [
                            'pluginOptions' => [
                                'autoclose' => true
                            ]
                        ]
]);


After saving my object, I can validate the saved date:

select id, myDate,from_unixtime(myDate) from myTable order by id desc;


So I am sure that the correct date is saved. But, If I edit my object, there is a wrong date displayed, it's always savedDate-1day.

my yii2-Settings should be correct too
'defaultTimeZone' => 'Europe/Amsterdam',


It would be great if someone could help me here,
ty!
0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,546
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 01 March 2018 - 01:13 PM

Hi there and welcome to the forums.

If your values saved in the database are correct the its likely the third-party widget you using is messing up your date.
0

#3 User is offline   rmist 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-March 18

Posted 02 March 2018 - 04:15 AM

Hi,
thanks for your reply. I changed my database scheme from unixtimestamp to mysql-date, and the error is gone since then.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users