We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

datefield with current date value

datefield with current value date

Set a datefield with the value of the current system date using phtml

<div class="row">
        <div class="large-2 columns">
            <label for="fieldContFecnaci">FECHA DE NACIMIENTO</label>
        </div>
        <div class="large-4 columns">
            <?php
echo $this->tag->dateField(array("CONT_FECNACI",  "id" => "fieldContFecnaci")) ?>
        </div>
<div class="large-2 columns">
            <label for="fieldContFecinsc">FECHA DE INSCRIPCION</label>
        </div>
        <div class="large-4 columns">
            <?php echo $this->tag->dateField(array("CONT_FECINSC", "id" => "fieldContFecinsc")) ?>
        </div>
    </div>

I previously used javascript. How would you do in Phalcon?

<script type="text/javascript">
    $(document).on('ready', function () {
    var now = new Date();
    var month = (now.getMonth() + 1);
    var day = now.getDate();
    if (month < 10)
        month = "0" + month;
    if (day < 10)
        day = "0" + day;
    var today = now.getFullYear() + '-' + month + '-' + day;
    $('#fieldContFecnaci').val(today);
    $('#fieldContFecinsc').val(today);
});

</script>

I can not use the function now gives me an error



43.9k
Accepted
answer

<?php echo $this->tag->dateField(array("CONT_FECINSC", "id" => "fieldContFecinsc", "value" => date("Y-m-d"))) ?>



81.2k

You help change the format to send to the database as need you to go as dd / mm / yyyy