I created a function to compare dates:
public function checkExpiredDate($cardDate) : bool
{
$currentDate = new DateTime();
$creditCardDate = new DateTime("{$cardDate->card_expiryYear}-{$cardDate->card_expiryMonth}-*last day from the month*");
echo $creditCardDate->format('Y-m-d'); exit();
return $creditCardDate->getTimestamp() < $currentDate->getTimestamp() ?? true;
}
I only have the month and year , not the day. I need to compare today's date with that date using only the month and year and the DateTime class . How can I do that ? Is there a way to get the last day from a month and year using the DateTime class? If I could get it someone using DateTime , my function should work .