Please i want to get value of month and year from this javascript code as PHP variable $mm = ? && $ yy = ? input name=\"startDate\" id=\"startDate\" class=\"date-picker
From the comment:
"I am using this html code"
Looking at your code you're not actually passing through variables called mm
and yy
(or month
for that matter) - that's not what datepicker.dateFormat
does - it merely formats the string going into your input field (e.g. startDate
) - so you're explicitly excluding the day.
You can pass that date to the server and load it into a DateTime
object.
You can use DateTime::createFromFormat()
to do this but you need to add 01 for the day when you create the object otherwise today's date will be used and that can lead to some unexpected results (e.g. the date being set to the 30th of February).
format('m')
// to output the year as 'yy'
echo $startDate->format('y');
}
You never have to use the day value stored in the DateTime
object but it does need to be there.
Example
If you wanted to put the mm/yy string back into your field after form submission, say it failed validation but you want to keep the data the user entered in the input:
format('m/y')) . "\"" :
"";
?>
class="date-picker" />
References