Page 1 of 1

Date comparision

Posted: Mon Jul 06, 2009 6:45 am
by nite4000
here is what i wanna do. I want to take the joindate and compare it to the current date if its been more then 15 days between the 2 then it will suspend. but not sure how to get it working. I am close i think.

<?php
$s = mysql_query("SELECT * FROM user WHERE id='2'") or die(mysql_error());
$info = mysql_fetch_array($s, MYSQL_ASSOC);
@mysql_free_result($s);


if ($info['joindate']) < = date("m-d-Y", 30*86400 + time());

(query here to update account to suspened)
}

?>


hope somone can give me a lil more insight as i am still lost some

Thanks

Re: Date comparision

Posted: Mon Jul 06, 2009 7:45 am
by iamngk
you can do with query itself.

you can get only 15 days passed person with following guery

SELECT * FROM user WHERE joindate > DATE_SUB(curdate(),INTERVAL 15 days)

or

SELECT *,IF(joindate > DATE_SUB(curdate(),INTERVAL 15 days),'YES','NO') AS exp FROM user WHERE id=2

$info['exp'] will give you 'YES' if that passed 15 days....

Re: Date comparision

Posted: Mon Jul 06, 2009 8:14 am
by nite4000
Thanks I will give that a try

Re: Date comparision

Posted: Mon Jul 06, 2009 8:51 am
by genconv
You can also use the DATEDIFF function in your SQL:

Code: Select all

SELECT * FROM user WHERE DATEDIFF(now(),joindate)>15
if you want to update the "user" table then you can use the following SQL query:

Code: Select all

UPDATE user SET suspend=1 WHERE DATEDIFF(now(),joindate)>15