Forum Moderators: coopster

Message Too Old, No Replies

MySql last month queries

         

FnTm

6:42 am on Aug 8, 2007 (gmt 0)

10+ Year Member



Is there any syntax that would do this form me?

because now I have to manually change the dati in the php file every month, for it to work.

My current syntax:

$sql_3="SELECT COUNT(distinct person_id) from request_rights where register_date < '2007-08-01 00:00:00'";
$select_3 = mysql_query($sql_3) or die("Nevar pieslēgties DB!");
$select_3_rez = mysql_fetch_array($select_3);

Habtom

7:04 am on Aug 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



register_date < '2007-08-01 00:00:00'

Give it a try with this, it takes the current time and subtracts one month to it:

register_date < date_sub(now(),interval 1 month)

. . .or you always want it to be from the begining of the month?

Habtom

FnTm

11:55 am on Aug 8, 2007 (gmt 0)

10+ Year Member



I'd like it to be from the begining till the end of last month.

Is it possible?

coopster

1:39 pm on Aug 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could use a BETWEEN [dev.mysql.com] expression.

FnTm

12:14 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



Bump.

the betwen statemnt is not what I really want. I need something that could stat, that i need to see visits between previous and this month,

exmaple:

It is august now, and i need to know visits between july,and august. So at the end of every month I have to manually change my script.

Help?

d40sithui

1:03 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



the register_date you're storing is in format yyyy-mm-dd right?
if so, try this
<?
$query = "SELECT COUNT(distinct person_id) from request_rights where substring(register_date,6,2) = substring(now(),6,2)-1";

?>