Set current date in Input type Date

Asked

Viewed 2,257 times

2

I want to set the current date in this input type date; using this way with php it only gives the value of the current date, but viewing shows only dd/mm/yyyy, but inspecting the code the value of "value" is with the current date. Someone can help me ?

 <input class='col-4' type='date' name='Dsaida' id='DSaida' value='<?php echo date("d/m/Y"); ?>'>

2 answers

4

You must pass the date in the patterns defined in RFC 3339, thus:

 <input class='col-4' type='date' name='Dsaida' id='DSaida' value='<?php echo date("Y-m-d"); ?>'>

The RFC 3339 is a profile of ISO 8601, and it defines a format for representing dates and times to the internet using the Gregorian calendar.

  • Thanks, it worked out

  • Just one detail: the format ano-mês-dia is called ISO 8601 (the American format would be mês/dia/ano). And the RFC 3339 is a profile of ISO standard 8601 (is as if RFC is an extension/subset of ISO, as it restricts some formats while allowing others, etc)

  • Thanks @hkotsubo, modified my reply.

0

If you are using Javascript you can do this gambiarra:

<script>    
//seta a data atual
     document.getElementById("campoData").value = value='<?php echo date("Y-m-d"); ?>';
</script>

Browser other questions tagged

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