I am trying to use the php DateTime objects modify function to modify he date to a specific date in the month i.e. 10th or 20th etc.
I have tried all of the following, none of which work:
$d = new DateTime();
$d->modify('10th day');
$d->modify('10th');
$d->modify('10th of this month');
$d->modify('10th of the month');
Assuming you don’t know the year and month (if you do, use
DateTime::setDate()), one way to do this would like this:I have a feeling that there’s also a way to do it strictly through the constructor, but like you, I couldn’t figure out the magic string. Odd that "first day of the month" works, but "tenth day of the month" does not.
Edit: Apparently it’s impossible to do this through the constructor. Even Rasmus suggests doing it this way instead.