Really simple Date Question!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Flashart
Forum Commoner
Posts: 71
Joined: Tue Oct 06, 2009 12:12 pm

Really simple Date Question!

Post 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
Flashart
Forum Commoner
Posts: 71
Joined: Tue Oct 06, 2009 12:12 pm

Re: Really simple Date Question!

Post 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:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Really simple Date Question!

Post by Weirdan »

Flashart wrote:when I should have been using 'Y-m-j'.
People usually use 'Y-m-d' to get ISO 8601 date.
Post Reply