dateTime values in settings page are always a day behind I've used this thread to successfully get my dateTime input fields to repopulate.

The problem I'm seeing now is that while values in the DB are correct, the field input values are always a day behind. 

For example, the data in my DB looks like:

....
"startDate":{"date":"5\/4\/2015"}
....


But, the value that is getting rendered in the filed (from my settings page) is this:

5/3/2015


If I save the settings (no errors). The values in the DB will be 5/3/2015 - but then the field on my settings page will show: 5/2/2015

EDIT

Thank you @carlcs, I am sure you are right - I'm just not doing it...right.

Here is what I have tried:

MyPlugin.php

// this returns nothing when logged in error_log
$settings['myStartDate'] = DateTime::createFromString($settings['seasonStartDate']['date'] );

// this returns the date, but one day in the past
$settings['myStartDate'] = new DateTime( $settings['myStartDate']['date'] );


In my defineSettings() method, I am setting myStartDate to a Mixed type as there is a bug with dateTime.

  ....
  'myStartDate' =&gt; array(
       AttributeType::Mixed
   ),
   ....


I'm not exactly sure where prepSettings() should live. Here is the whole file:

MyPlugin.php

public function defineSettings()
    {
        return array(
            'myOpenings' =&gt; array(
                AttributeType::Number,
                'required' =&gt; true
            ),
            'myStartDate' =&gt; array(
                AttributeType::Mixed
            ),
            'myEndDate' =&gt; array(
                AttributeType::Mixed
            )
        );
    }

    public function getSettingsHtml()
    {
        $settings = $this-&gt;getSettings();


        if ( isset( $settings['myStartDate']['date'] ) )
        {
            $settings['myStartDate'] = DateTime::createFromString( $settings['myStartDate']['date'] );
         // $settings['myStartDate'] = new DateTime( $settings['myStartDate']['date'] );

            error_log($settings['myStartDate']);
        }

        if ( isset( $settings['myEndDate']['date'] ) )
        {
            $settings['myEndDate'] = new DateTime( $settings['myEndDate']['date'] );
        }

        return craft()-&gt;templates-&gt;render( 'plugin/_settings', array(
                    'settings' =&gt; $settings,
                ) );
    }


EDIT/SOLUTION

@carlcs and @Mats Mikkel Rummelhoff for their help. 
For anyone coming to this post, here is what my "final" main plugin class file looks like hope it helps.

MyPlugin.php

....
public function defineSettings() {
    return array(
        'myOpenings' =&gt; array(AttributeType::Number, 'required'=&gt;true),
        'myStartDate' =&gt; array(AttributeType::Mixed, 'required'=&gt;true),
        'myEndDate' =&gt; array(AttributeType::Mixed, 'required'=&gt;true)
    );
}

public function getSettingsHtml() {
    $settings = $this-&gt;getSettings();

    if(isset($settings['myStartDate']['date']))
    {
        $settings['myStartDate'] = DateTime::CreateFromString($settings['myStartDate']);
    }

    if(isset($settings['myEndDate']['date']))
    {
        $settings['myEndDate'] = DateTime::CreateFromString($settings['myEndDate']);
    }

    return craft()-&gt;templates-&gt;render('myplugin/_settings', array(
        'settings' =&gt; $settings
    ));
}
Update: Sorry dragonslovetacos, I just tested this and found out it doesn't work as expected. It probably is the right way to handle DateTime values when saved with attribute type DateTime.



You're probably not preparing the value for your template. Before saving your date to the database you convert it to a DateTime object and your system timezone gets calculated into the value. You now need to do the same thing before you render that value in your template.

Or maybe it's the other way round, and you're preparing the value for your template and save it unprepared.

Anyways, the helper function DateTime::createFromString() should be applied to your value in both, prepSettings() and getSettingsHtml().