1

In the db_schema :

 <column name="holidays_start_date" nullable="true" xsi:type="date"  comment="holidays_start_date"/>

I created a field of type date in an admin form :

      <field name="holidays_start_date"  sortOrder="3">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="label" xsi:type="string" translate="true">Start holidays Date</item>
                    <item name="formElement" xsi:type="string">date</item>
                    <item name="source" xsi:type="string">vendor</item>
                    <item name="dataScope" xsi:type="string">holidays_start_date</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
 <item name="options" xsi:type="array">
                        <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                    </item>
                </item>
            </argument>
        </field>

When for example i choose the 22 of august 2022, , when i want to save the form , i have got this error :

main.CRITICAL: Exception message: DateTime::__construct(): Failed to parse time string (26/08/2022) at position 0 (2): Unexpected character

But when I use a date like the first of the august 2022, it works.

Could you help me please? I dont know how to change the date format . :(

2 Answers 2

1

I found an answer but it s not logical at all : If i put :

        <column name="holidays_start_date" nullable="true" xsi:type="date"  comment="holidays_start_date"/>

And

  <field name="holidays_start_date" sortOrder="60" formElement="date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">holidays_start_date</item>
                    <item name="source" xsi:type="string">vendor</item>
                    <item name="options" xsi:type="array">
                        <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                        <item name="timeFormat" xsi:type="string">hh:mm</item>
                        <item name="showsTime" xsi:type="boolean">true</item>
                        <item name="minDate" xsi:type="string">new Date()</item>
                    </item>
                </item>
            </argument>
        </field>

It works But i set at false :
<item name="showsTime" xsi:type="boolean">true</item> It does not work anymore . really strange !

2
  • It its helps you can mark this an answer
    – Rana Zain
    Aug 27, 2022 at 12:05
  • Now its working or not
    – Rana Zain
    Sep 15, 2022 at 8:09
1

You can use this :

<field name="display_from" sortOrder="60" formElement="date">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string">Display From</item>
            <item name="source" xsi:type="string">hotdeal</item>
            <item name="options" xsi:type="array">
                <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                <item name="timeFormat" xsi:type="string">hh:mm</item>
                <item name="showsTime" xsi:type="boolean">true</item>
                <item name="minDate" xsi:type="string">new Date()</item>
            </item>
        </item>
    </argument>
    <settings>
        <validation>
            <rule name="required-entry" xsi:type="boolean">true</rule>
        </validation>
        <dataType>timestamp</dataType>
        <dataScope>display_from</dataScope>
        <label translate="true">From</label>
    </settings>
</field>

For db schema

<column xsi:type="timestamp" name="display_from" comment="From Time"/>

For Only date you can use this :

<form>
    ...
    <fieldset>
        ...
        <field name="date_example" formElement="date">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">some_source</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="validate-date" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
                <label translate="true">Date Example</label>
                <visible>true</visible>
                <dataScope>some_scope</dataScope>
            </settings>
        </field>
        ...
    </fieldset>
6
  • Tahnks for your help but i want a date and not a datetime :( Aug 26, 2022 at 14:20
  • This may help you magento.stackexchange.com/questions/217353/…
    – Rana Zain
    Aug 26, 2022 at 14:31
  • I updated the answer you can check
    – Rana Zain
    Aug 26, 2022 at 14:36
  • If this helps you a little bit, please mark this an answer
    – Rana Zain
    Aug 29, 2022 at 5:55
  • Hi , rana Zain , it still doesn t work :( Exception message: DateTime::__construct(): Failed to parse time string (30/11/2022) when i use your solution. Aug 29, 2022 at 8:46

Your Answer

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

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