Display input value date type

Asked

Viewed 6,722 times

4

I have the following input:

<p>Data Saída:</p>
<input type="date" maxlength="10" id="saida" name="saida" value="29/01/2016"/>

It is being shown as follows:

inserir a descrição da imagem aqui

But I want to display inside your input value and not the dd/mm/yyyy

  • edits the question and puts the value that is in $Dtsaida

  • Okay, it’s redacted.

  • 2

    use the American date format

2 answers

4

For this it is sufficient that the content of the variable $Dtsaida is in YYYY-MM-DD format see example below:

<p>Data Saída:</p><input type="date" maxlength="10" id="saida" name="saida" value="2016-01-16"/>

Considering your result you need to remove the minutes from the print for such try something similar to this: echo

<p>Data Saída:</p><input type="date" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="<?php date_format($DtSaida, 'Y-m-d'); ?>"/>
  • Because it is back to the American standard because it continues the dd/mm/yyyy in place of the value. Follow: <p>Data Saída:</p><input type="date" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="2016-01-21 00:00:00.000"/>&#xA; took value but the input remains equal.

  • @Kevin. F you need to format the output added a snippet with the example in the above answer

  • I just want to take these characters (dd/mm/yyyy) out of the input so that the value that is inside the value appears. It follows error that gave <p>Data Saída:</p><input type="date" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="<br />&#xA;<b>Warning</b>: date_format() expects parameter 1 to be DateTimeInterface, string given in &#xA;"/>&#xA;

  • what type of your $Dtsaida variable is if it is a string look at this reference: http://php.net/manual/en/datetime.format.php

  • She’s like INT

  • It makes no sense if she’s as int as her output would be 2016-01-21 00:00:00.000?

  • It is but it is as int

  • @Kevin. F why don’t you put the $Dtsaida type as datetime?

Show 3 more comments

1


Solved the problem follows the right code:

$data_formatada = DateTime::createFromFormat('d/m/Y', $DtSaida);

<input type="date" maxlength="10" onkeypress="return dateMask(this, event);" id="saida" name="saida" value="<?php echo $data_formatada->format('Y-m-d'); ?>"/>

Browser other questions tagged

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