Search code examples
phphtmlmysqlinputmonthcalendar

Type month of html not allowing to fetch dynamic dates from database?


I am using type=month for input value. I have finished storing data into db but on the time of fetching data its not showing my db's date on form.

SELECT * ,DATE_FORMAT(end_date, '%M  %Y') AS endDate FROM vat_report

I am using above format to fetch date. If I echo endDate it shows me proper date like January 2018, February 2019 etc whatever is in the database but on input box its not showing data. If I change type = month to type = text then it is displaying my date. But I only want month type on input box so that on update too user can update date in M-Y format.

<td><input type="month" name="end_date"  value="<?php echo $end_date1;?>"/></td>

Above is my html code for showing date in month name - year format. I can't find any solution for this. It shows only some ------ ---- something like this inside input box


Solution

  • You say that if you echo endDate it shows you the proper date like "January 2019". Don't you mean echo $endDate instead?

    In your inline PHP, you do <?php echo $end_date1;?>, could the issue be that you added a 1 to the end?

    If you only want to show the month, you should use SELECT * ,DATE_FORMAT(end_date, '%M') AS endDate FROM vat_report