-1

I'm looking for a way to filter for events that happened between previous September (1st) and upcoming September (1st) every year. Since the filter is already part of an existing piece of code I can ony add a fixed date (timestamp) or use a relative date that runs through php strtotime. I can't run any php in the field.

Because a timestamp is fixed for a set year, I want to use relative dates to make this filter work every year.

I have tried to build this filter using simple things like [last/next] September, but that is invalid strtotime syntax.

From there I tried things like 9/1 [last/this/next] year. They were valid, but since I can't use logic to determine which one to use, it is not good.

  • For dates prior to this year September 1st the filter would be 9/1 last year>9/1 this year
  • For dates past September 1st this year it is 9/1 this year>9/1 next year.

So to summarize, I am looking for a relative date string (strtotime) to get the previous September 1st and a string for the upcoming September first. (If they exist.)

Neograph734
  • 1,714
  • 2
  • 18
  • 39
  • you need to post some data as i don't really understand. maybe $last = date("Y-m-d",strtotime("last Monday")); [date](http://uk1.php.net/manual/en/function.date.php) [strtotime](http://uk1.php.net/manual/en/function.strtotime.php) – amigura Jun 15 '13 at 14:11
  • i know but still scratching head ;). you need year to make it work – amigura Jun 15 '13 at 15:18

1 Answers1

0

i guess you want dates in between 2012/09/01 - 2013/09/01.

you can use string in link if that's what your talking about, but you need years.

$this_year='2013/09/01'; 
$last_year = date("Y-m-d",strtotime("$this_year - 1 year"));
$next_year = date("Y-m-d",strtotime("$this_year + 1 year"));


echo 
"<a href=\"?date_filter=$this_year\"> last year</a> 
<a href=\"?date_filter=$this_year\"> this year</a>
<a href=\"?date_filter=$next_year\"> next year</a>
";


if(strtotime($this_year) <= strtotime($filter_date) and strtotime($filter_date) >= strtotime($last_year))
{
    // dates in between 2012/09/01 - 2013/09/01 
    }


    if(strtotime($this_year) >= strtotime($filter_date) and strtotime($filter_date) <= strtotime($next_year))
{
    // dates in between 2013/09/01 - 2014/09/01 
    }

if you are getting data from database then use code below as its easier.

SELECT * FROM table_name WHERE 'date_field' BETWEEN ('$this_year') and ('$last_year ')
amigura
  • 541
  • 3
  • 6
  • For this year I want them between 2012/09/01 - 2013/09/01. After 2013/09/01, I want them for 2013/09/01 - 2014/09/01 etc. I thought of similar constructions, but I can't use any php, only a string that runs through strtotime. I guess it is impossible though... – Neograph734 Jun 15 '13 at 15:35