XF 2.2 Xf dateinput format and its saving process

FoxSecrets

Active member
I am trying to show date 1 year from now and save it in unix timestamp, but no success.
The form below shows me "Jul 28, 2024", but when I pickup any date it shows in different format e.g. 2024-07-28.

How to show and pickup on the same format?

Code:
<xf:dateinput name="expiration" id="expiration" value="{{ date($xf.time + 31536000) }}" required="true" />

And during the saving process, it shows "now plus 20 hours", non sense.

How to correctly save it in unix timestamp format?

Code:
$input = $this->filter([ 
            'expiration'    => 'uint',
        ]);

        $input['expiration'] = strtotime($input['expiration']);
 
Last edited:
You can pass a format to the date function:

HTML:
<xf:dateinput name="expiration" value="{{ date($xf.time + 31536000, 'Y-m-d') }}"
    required="true" />

You can use the datetime filter type to get the timestamp:
PHP:
$expiration = $this->filter('expiration', 'datetime');
 
You can pass a format to the date function:

HTML:
<xf:dateinput name="expiration" value="{{ date($xf.time + 31536000, 'Y-m-d') }}"
    required="true" />
Using this US format works, however I'd like to use the format 'd-m-Y' and when I pickup any date, it shows back to Y-m-d, also calendar shows year 1934 (not 2024). Is there anyway to use 'd-m-Y'?
 
It's not very simple to change the display format of the form input (you'd have to extend the XF.DateInput JS handler), and the wire format will always be Y-m-d per the HTML5 spec for date inputs. However we have moved away from Pikaday in favor of native date inputs for XF 2.3, which will display the value based on your browser locale settings:

screenshot-eejymK.webp

When displaying dates in other areas, XF will generally use the format defined in the language settings.
 
Back
Top Bottom