INPUT VALUE with date format Y-m-d, but when displaying on the screen show in the format d / m / Y

1

Currently my INPUT is like this, but it's on the screen in this Ymd format, is there any way to make it display the date in the format d / m / Y, but continue with the value in Ymd format?

<input type="text" name="data" value="<?php echo date('Y-m-d');?>" placeholder="Data">
    
asked by anonymous 12.08.2018 / 05:30

1 answer

1

Although I find it better to convert the value ...

You can create 2 different inputs. One with the value that will be presented and another that is hidden with the value that will be used.

// input escondido 
<input type="hidden" name="data" value="<?php echo date('Y-m-d');?>"/>

// input que mostra o valor
<input type="text" name="" value="<?php echo date('d/m/Y');?>" placeholder="Data"/>

Result

<input type="hidden" name="data" value="2018-08-12"/> 
<input type="text" name="" value="12/08/2018" placeholder="Data"/>

You can also use <input type="date"/>

<input type="date" name="data" value="<?php echo date('Y-m-d'); ?>"/>

But it's only for version 5 of HTML and its interface support is patchy.

    
12.08.2018 / 05:40