Search code examples
phphtmlmysqlif-statementecho

Echo a date in input type inside a echo with Y-M-D format


I already echo a date but it doesn't have a right format for me which is Y-M-D I already specify the format on my variable but when I call the variable to be a value of my input type on my echo it doesn't give the right format. Hope someone help me . Here is my code

<?php
$last_covered=strtotime("+3 Months"); date("Y-m-d", $last_covered);
if ($statusv=='Newly-Registered') echo "<input type='text' class='form-control' name='last_covered' value ='".$last_covered."'>";

Solution

  • you may try this

    <?php
    $last_covered = date("Y-m-d", strtotime("+3 Months"));
    if (!empty($statusv) && ($statusv=='Newly-Registered')) {
    echo "<input type='text' class='form-control' name='last_covered' value ='".$last_covered."'>";
    } else {}
    ?>
    

    you have undefined variable on echo line may fix variable $last_covred to $last_covered