OK, so it turns out to be a PHP issue, not an EM bug, which is why we had such a hard time reproducing this, and also why some see it working on some sites and not on others. The issue specifically affects PHP versions 5.3 – 5.5.
If you’re running PHP 5, we recommend you run the latest version of that version because all other versions are already not supported anymore. However, we’ve fixed the issue anyway.
We’ve just release a new dev version 5.9.5.1 which has the fix. You can upgrade your site with a few clicks as per these instructions.
In case you’re interested, here’s a proof of concept which shows with regular PHP functions why this is not working as expected:
<?php
echo "PHP Version is : ". phpversion().'<br>';
$DateTime = new DateTime("2018-07-02");
echo '<strong>$DateTime = new DateTime("2018-07-02");</strong><br>';
echo '<strong>echo $EM_DateTime->format("Y-m-d");</strong><br>';
echo $DateTime->format("Y-m-d");
echo '<br><strong>$DateTime->modify(\'first day of this month\')->setDate( 2018, 7, 22 );</strong><br>';
$DateTime->modify('first day of this month')->setDate( 2018, 7, 22 );
echo '<strong>echo $DateTime->format("Y-m-d");</strong><br>';
echo $DateTime->format('Y-m-d');
die();
Paste this into a new .php file somewhere on your server and visit it directly and see the results.