What I have: I have an existing cron job file that runs daily every 15 minutes (e.g. 1.10pm, 1.25pm, 1.40pm, 1.55pm), to check in the database for emails to be sent. I am using PHP and mySQL.
My issue: Due to a limit by the hosting, I have to use the same cron job file for another task - check the database at every end of the month.
My question 1: I only want the check to be done once on that day - would my following solution work? If I don't want to update the database that I have done the check already, I will have to set the task to only be done if the time now is equal to 8.55am (a timing that the cron job would run at). So if the cron job runs at 8.55am, it would do
$TimeNow = new DateTime();
$TimeNow = $TimeNow->format('H:i');
$TimeToRun = new DateTime('8:55');
$TimeToRun = $TimeToRun->format('H:i');
if ($TimeNow == $TimeToRun) {check database}
My question 2: Would the following work to check if it is the end of the month? What can I do to check if this works because it is not the end of the month now?
if(gmdate('t') == gmdate('d')){}