cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.4.2 invalid date format by default, can't change date format in UI component, Magento bug?

Magento 2.4.2 invalid date format by default, can't change date format in UI component, Magento bug?

I would like to specify the date format for a new date field in my CMS page form. I have created a new cms_page_form.xml field which links to a date field in the MySQL database table cms_page. However, MySQL rejects the field because it is in the wrong format. I have tried setting the format in many different ways: https://i.imgur.com/xjtrrYc.png (also without the item options array), literally spending hours trying to set it in cms_page_form.xml with the official documentation for the Date component not providing much of any help: https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-date.html


I have even tried creating my own UI component (also specifying the new component /form/element/date etc of course) with just time as an example, and just time does work: https://i.imgur.com/PhrWqcp.png however when I change it to use date and specify the custom date format in JavaScript, it still doesn't work: https://i.imgur.com/R1XuXYW.png it just uses today's date in the wrong format: https://i.imgur.com/elamryD.png


Here is my cms_page_form.xml with the date formatting not working: https://i.imgur.com/xjtrrYc.png


When I load the CMS page, by default, it displays "Invalid date": https://i.imgur.com/kVv7I2o.png then quickly changes over to today's date - in the wrong format: https://i.imgur.com/OcfoH0E.png

All I want is a date input with the format of yyyy-MM-dd in my CMS page form in Magento 2.4.2

If anyone could help me with this I would really appreciate it.

Thanks.

2 REPLIES 2

Re: Magento 2.4.2 invalid date format by default, can't change date format in UI component, Magento

Add date Format

<column name="run_time" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="sortOrder" xsi:type="number">60</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Run Time</item>
<item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY hh:mm:ss a</item>
</item>
</argument>
</column>

Now delete the records that you find from a ui_bookmark table.

Clear the cache

See more: https://www.screencast.com/t/qePBLRpe27

If issue solved, Click Kudos & Accept as Solution.
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool

Re: Magento 2.4.2 invalid date format by default, can't change date format in UI component, Magento

Hi,

Nope, that didn't help, I'm still experiencing the problem I posted about.

Cheers.