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

Asked

Viewed 114 times

1

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

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

1 answer

1


Although I think I’d better convert the value...

You can create 2 different inputs. One with the value that will be displayed and the other 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"/>

Upshot

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

You can also use the <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 irregular.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.