在php中以mm-yyyy格式将字符串转换为日期

I have $year and $month as two variables. I want to convert them into date so that I can insert it into mysql table. I just want to store mm-yyyy in mysql.Is it possible in php?

$date = "$year-$month-01";

If you plan on storing it in a real 'date' field, you must have a day of the month too.

MySQL displays DATE values in ‘YYYY-MM-DD’ format.

So if you want it as a DATE, you have to put a day in your date like : $date = "$year-$month-$day".

If you don't want it as a DATE, you can store it as a 'MM-YYYY' like that : $date = "$month-$year".

After, you just have to make your MYSQL Query and it will work.