Page 1 of 1

Really simple Date Question!

Posted: Tue Jun 21, 2011 3:30 pm
by Flashart
For the life of me I can't remember how to structure this. Please someone rescue me from my insanity!

I am trying to php code a sql script that retrieves the last 7 days of data. I have two dates, $startDate and $endDate like ths:

Code: Select all

$startDate=date('Y-M-D', strtotime('-1 week'));
$endDate=date('Y-M-D', strtotime('-1 day'));
I have a sql script like this:

Code: Select all

$query  = "select account as account,
campaign as campaign,
sum(impressions)impressions,sum(clicks)clicks,sum(cost)cost,avg(avg_position),sum(conv_mpc)conversions
From ppc_data
where date between '".$startDate."' and '".$endDate."'
group by campaign
order by conversions desc;
";
But this does not work! I get a blank page where I should get results. Please can someone tell me where I am going wrong?!

Thanks
Peter

Re: Really simple Date Question!

Posted: Tue Jun 21, 2011 3:59 pm
by Flashart
ah just realised I was using 'Y-M-D' When I should have been using 'Y-m-j'. Now going to hit my head like this -> :banghead:

Re: Really simple Date Question!

Posted: Tue Jun 21, 2011 6:21 pm
by Weirdan
Flashart wrote:when I should have been using 'Y-m-j'.
People usually use 'Y-m-d' to get ISO 8601 date.