...

View Full Version : See if member is new within last month



JohnDubya
01-24-2007, 12:21 AM
I had to write code that would take the date the user was created (from a date column in MySQL) and see if he was within a month of having joined, and therefore new to my site. If he is new, it will make his type "new," to distinguish him from long-time members. Here's the code for it.



// Get the CreatedDate from the MySQL database...do a query on that field for whatever
// record you want. For simplicity, I've just gotten today's date in the normal format.

$created_year = date('Y');
$created_month = date('m');
$created_day = date('d');

// Add 1 month to the created month.

$time_as_new = strtotime("+1 month", mktime(0,0,0,$created_month,$created_day,$created_year));

// If the time allocated (1 month) for a user to be new is more than the current time,
// make the member's type "new."

if ($time_as_new >= time()) {
$member_type_new = 'New Member';
}


It took me forever to figure this out, so I hope that helps someone! If you notice any errors or improvements, please critique away.

nexosis
03-18-2007, 05:32 PM
I think many forums support this, BTW, nothing to comment at all, nice.
used phpdate?

JohnDubya
03-19-2007, 12:50 AM
Nope. What is phpdate?

nexosis
03-22-2007, 11:04 AM
what is phpdate?

http://php.net/date

Nightfire
03-22-2007, 02:57 PM
I'm sure there's a way you can get all that straight from a db query, but I can't remember how it's done lol.

It'll be in here somewhere
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum