1

I created a custom module to update news and stories to magento 2 website.I have the date field in my form( main.php ).

 $dateFormat = $this->_localeDate->getDateFormat(
        \IntlDateFormatter::MEDIUM
    );
 $timeFormat = $this->_localeDate->getTimeFormat(
        \IntlDateFormatter::MEDIUM
    );

 $fieldset->addField(
        'news_date',
        'date',
        [
            'name' => 'news_date',
            'label' => __('News date'),
            'title' => __('News date'),
            'date_format' => $dateFormat,
            //'time_format' => $timeFormat,
            'required' => true,
            'disabled' => $isElementDisabled
        ]
    );

My grid file is like below.

this->addColumn(
        'news_date',
        [
            'header' => __('News date'),
            'index' => 'news_date',
            'type'      => 'date',
        ]
    );

What my issue is actual saved date is not showing in grid.if i save the news for Oct 29, 2019 grid will show Oct 28, 2019. Below attached two images.

form enter image description here

Grid enter image description here

What is the issue behind this? Can anyone please help me?

1 Answer 1

1

This happening because of Time Zone Problem:

Go to Configuration > General > locale Options > Time Zone

Set the Server time zone and Magento Time zone same for this Problem.

Hope this will help You!!

2
  • thank you. this helped me
    – Mujahidh
    Commented Nov 8, 2019 at 9:49
  • My Pleasure.... Commented Nov 8, 2019 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.