Current date in input html

3

I'm looking for the field:

<input type="date" id="fecha" name="fecha"

Type date show the current system date, thanks.

    
asked by Cesar Reyna 09.08.2018 в 21:54
source

3 answers

4
<input type="datetime" name="fecha"  value="<?php echo date("Y-m-d\TH-i");?>">

You could try my estimate with the previous code.

    
answered by 09.08.2018 в 22:05
0

Hello, in case you are not working with a local server, you can also do it with js with this code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$( document ).ready(function() {

    var now = new Date();

    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);

    var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
    $("#fecha").val(today);
});
</script>

greetings

    
answered by 09.08.2018 в 22:41
0

You can try this code, using the ** date '* php

<input type="date" 
       id="txtfecha" 
       name="txtfecha" 
       class="form-control" 
       value="<?php echo date("Y-n-j"); ?>" 
       required/> 
    
answered by 09.08.2018 в 23:16