4

if now is 2016-02-10 I need for return 2015-07-01 (or 2015-07-10)

strtotime('july'); // returns 2016-07-10
strtotime('last july'); // does not work
strtotime('july 2015'); // I have not '2015' for query. 
//Only if compare date (month) now and month needed. In looks not realy straight way.
scrache
  • 113
  • 1
  • 1
  • 8

1 Answers1

4

What happens if you are past july this year? Would it then need to return july 2016, or is it always the year before?

If so, you can use 'july last year':

<?php
$returnValue = strtotime('july last year');

Based on needing to return this year's july as well:

<?php
$returnValue = strtotime('july '. (date("n") >= 7 ? 'this' : 'last' ) .' year');
Liam Wiltshire
  • 1,254
  • 13
  • 26