How can I return data for the current month in MySQL using timestamp and PHP?

This should address all other data with PHP/MySQL timestamp I have. Basically I use the timestamp feature in MySQL and PHP

I insert using now for MySQL:


or something like this in PHP:

$date=date("Y-m-d H:i:s");

This is some of my data:

Id          AdId    Unique Md5                                              Date                Stamp                                   IP

    61860       207     92cea3a296fdc76bac6fda219xxxxxx     2012-12-01  2012-12-01 17:48:31     74.125.181.xx
    61859       208     abe3aec5c24301db2d5803a310xxxxxx  2012-12-01    2012-12-01 17:48:31     74.125.181.xx
    61858       207     c93c67a013c64df53cbeec9346xxxxxx  2012-12-01    2012-12-01 17:48:11
    61857       207     596cf87f2405874c7172f6d0dcxxxxxx    2012-12-01  2012-12-01 17:47:54
    61856       212     bbba41c211e2829d622c55d00dxxxxxx  2012-12-01    2012-12-01 17:47:17

This is one of my queries. Basically I am trying to get row total for all the AdId with 207 and the timestamp of this month (2012-12)

SELECT COUNT(adid) AS hits FROM `ha1`.`adviews` WHERE `adid`='212' AND `stamp`='2012-12'

It returns 0 results. I was going to do:

$currentDate=date("Y-m-d H:i:s");

$trafficsql=mysql_query("SELECT COUNT(adid) AS hits FROM `".$dn."`.`adviews` WHERE `adid`='".$rz["id"]."' AND `stamp`='".$currentMonth"'");
    echo $vss["hits"];

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.