Can someone help me please, I need a function or a way in PHP, to exclude the day from a given date regardless of its format.
Thank you.
try this
$newdate = date("m-Y",strtotime($date));
I ran into this as well, and made preg match to check for 2 date formats with year notation yyyy. Not the solution I'd prefer, but it works for me. Downside is that you have to define all the date formats and it depends on yyyy notation.
// check form to be yyyy-mm-dd
if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', $date)){
$date = date("Y-m", $date);
}
// check form to be mm-dd-yyyy
elseif (preg_match('/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/D', $date)){
$date = date("m-Y", $date);
}