using mktime() help - how many users joined today

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
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

using mktime() help - how many users joined today

Post by will83 »

Hi there,

I am trying to create somecode that will me how users have signed up today. The forum uses the unix timestamp when a new user joins. I have this code so far:

Code: Select all

$today = mktime(0,0,0,date("m"),date("d"),date("Y")); 

$today = date('dS M Y', $today);   

$query = "SELECT joindate FROM table WHERE joindate = '$today'"; 
$result = mysql_query($query, $conn); 
$todayusercount = mysql_num_rows($result); 

echo "<h1>$todayusercount of which have joined today!!</h1>";

However it is not working because it is looking for that particular timestamp and not a timestamp that falls within today's date.

Can anybody give a suggestion?

thanks, Will
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What version of MySQL are you running? There are some pretty nifty date functions that can help you with this in version 4.1+.
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Post by will83 »

Hi, not sure but assume it's 4 at least.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you run the following queries please?

Code: Select all

SELECT VERSION();
SHOW CREATE TABLE `table`;
Substitute the real table name for "table."
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

There may be an easier way, but one thing you could do is create two variables, $today_min and $today_max:

Code: Select all

$today_min=mktime(,,,0,0,0)
$today_max=mktime(,,,11,59,59)
and in your SELECT statement use

Code: Select all

'...WHERE joindate => '$today_min' AND joindate =< '$today_max'
I haven't tried that, and the above may contain syntax errors, but you get the idea?

Don
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Should be:

Code: Select all

WHERE joindate >= '$today_min' AND joindate <= '$today_max'
EDIT: also, mktime would be:

Code: Select all

$today_min = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$today_max = mktime(11, 59, 59, date('m'), date('d'), date('Y'));
Post Reply