Reputation: 1081
I can create DateTime
Objects with string parameter to get dates, like this.
$first = new \DateTime("first monday of july 2015");
$second = new \DateTime("last tuesday of july 2015");
$third = new \DateTime("first monday of january 2015");
But how can i get penultimate monday of july?
Upvotes: 1
Views: 462
Reputation: 10330
$penultimateMonday = new \DateTime("last monday of july 2015 -1 week");
echo $penultimateMonday->format('Y-m-d');
Output
2015-07-20
Upvotes: 2
Reputation: 208
You can do it by DateInterval example
$last = new \DateTime("last monday of july 2015");
$penultimate = $last->sub(new \DateInterval('P7D'));
Variable $penultimate will be last Monday minus 7 days what is penultimate Monday of july
Upvotes: 1
Reputation: 141
The penultimate mondoay of july is always 7 days before the last monday in july, so you can do:
$last = new \DateTime("last monday of july 2015");
$penultimate = $last -7;
Upvotes: 0
Reputation: 1864
echo $test = date("Y-m-d",strtotime("last monday of july 2015"));
Upvotes: -1