replace curdate() - 带$ variable - interval的区间

The code below is to select and then echo stuff from my db grouped by either weeks or months. I have a couple of more of these and then use offset to get the second week etc.

FROM my_db WHERE DATE >= CURDATE() - INTERVAL 10 ".$grouping1." GROUP BY ".$grouping."(DATE) order by DATE desc limit 1

I have two questions:

  1. I would like to exchange curdate() with a variable instead so that we are able to "pick a startdate" and then look 10 weeks/months back from that date.

  2. Is there a simpler/better way to do this?

I've tried to exchange the curdate with a variable like this:

FROM my_db WHERE DATE >= '". $startdate ."' - INTERVAL 10 ".$grouping1." GROUP BY ".$grouping."(DATE) order by DATE desc limit 1

but the weeks/months stay the same even though the variable (start date) changes.

Edit: My $startdate variable is formatted like this 2013-05-07 and the DATE column in the mysql db is of date format.

Peace /Adis

Something like:

FROM my_db WHERE DATE >= '".date(Y-m-d, strtotime($my_date))."'

Will work

Try this.

This will subtract 10 months from current date

FROM my_db WHERE DATE >= '".date("Y-m-d", strtotime("-10 months"))."'

This will subtract 10 weeks from current date

FROM my_db WHERE DATE >= '".date("Y-m-d", strtotime("-10 weeks"))."'