0

I have a date value in PHP variable $datewhich want to show in the input having type date with following code:

<input type="date" value="<?php echo $date;?>" name="date">

I want to show the value which is in $date variable in the input textbox of date. Also, user should be able to pick the value from the date picker, which is working fine, but i want a date should be there. I looked at previous questions, they assign the today's value, but i want to use the value i have in $date variable.

sman
  • 3
  • 4
  • Should most likely still be closed as a duplicate of https://stackoverflow.com/questions/6982692/how-to-set-input-type-dates-default-value-to-today, even if the value you want to set is _not_ today. The rest of the info in there is still what is mainly relevant to your question. – 04FS Nov 29 '19 at 14:55
  • Possible duplicate of [How to set input type date's default value to today?](https://stackoverflow.com/questions/6982692/how-to-set-input-type-dates-default-value-to-today) – Rockcat Nov 29 '19 at 15:10

2 Answers2

0

You can do something like

<?php 
$timestamp = time();
$date = date( "Y-m-d", $timestamp );
?>

<input type="date" value="<?php echo $date; ?>" name="date">

Explanation

date( "Y-m-d", $timestamp ) formats a timestamp to the appropriate format ( e.g. 2019-11-29 ).

Resources

Rob Monhemius
  • 4,822
  • 2
  • 17
  • 49
0

Try RMo solution or try.

<input name="date" type="date" value="<?php echo date('F d, Y'); ?>" />

Where:

  • F stands for Month in words
  • d stands for days in number,
  • Y stands for year in 4 digit number.
Two
  • 512
  • 4
  • 17