MyBB Community Forums

Full Version: Need a way out to parse the number of days
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Am working over a plugin where a user specifies the number of days (say 2), and it compares with the registration date of users, so you can say that am trying to calculate if the days passed are more than 2 (specified in settings) since when the user registered. For example, if user registered on 22 November, and number of days are specified as 2 (in settings) and if today's date is 25 (> registration date) it does the specified action. Am doing something like:

if($days > $registrationdays)
{
return $somequery;
}

Oh, and am using below date parser but I don't think it would work in this case when comparing:

$regdate = my_date($mybb->settings['dateformat'],$user['regdate']); (for getting user's registration date)

and

$time = my_date($mybb->settings['dateformat'],$registrationdays); (getting user specified value of days.)

Any help would be appreciated.

If this is done, this would a marvelous invention and a small gift to MyBB from my side.

Thank you.
Try to see this plugin: http://yaldaram.com/showthread.php?tid=224 I'm using quite similar thing in the mentioned plugin.
Thanks for that man, I'd try that now. And also, I've defined a query to move from one usergroup to another.

Condition:

if($days > $registrationdays)
{
return $somequery;
}

In above condition, $somequery is for moving usergroups from one to another. I am not sure that if I used return $somequery, would that move usergroups to specified one in query or the move won't take any effect?
You've to use update_query, like this;
$update_usergroup = array(
   "usergroup" => "3"
);
$db->update_query("users", $update_usergroup, "uid='{$mybb->input['uid']}'");

Make sure you've defined the uid as $mybb->input['uid'] otherwise it'll return empty.
Am using the query:

$somequery = $db->query("UPDATE * FROM `".TABLE_PREFIX."_users SET usergroup=x WHERE usergroup=y");

and than calling it with while $move = somequery and all that. Isn't it right and won't it work?
simple

if($user['regdate'] != 0 && (TIME_NOW - $user['regdate']) > (86400 * $mybb->settings['registrationdays']))
{
    //do your thing
}

TIME_NOW is a MyBB defined value in seconds.
regdate is defined in seconds
86400 is seconds per 24 hours
the setting is the number of days per ACP
Okay pavemen, I'd try that now, thank you. And would the usergroup update query I posted just above your post would work?
(2011-11-29, 06:32 PM)crazy4cs Wrote: [ -> ]Okay pavement

!!!



Toungue
Heck, my early morning typos.

edit: Things seems going well now, I'll finish it off in some hours (sleep time) and would create a thread for beta testing. Smile

Thank you guys.
(2011-11-29, 06:32 PM)crazy4cs Wrote: [ -> ]Okay pavemen, I'd try that now, thank you. And would the usergroup update query I posted just above your post would work?

and that query you wrote will update ALL users in the one group to the other. You should also use the built-in update_query function


//$oldgroup is your "Y"
//$newgroup is your "X"
//$uids is a single UID or a CSV list of UIDs that you build from a query result or other method

$update_array = array("usergroup"=>intval($newgroup));

$db->update_query("users", $update_array, "usergroup=".intval($oldgroup)." AND uid IN ({$uids})");
Pages: 1 2