Date comparision

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
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Date comparision

Post 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
iamngk
Forum Commoner
Posts: 50
Joined: Mon Jun 29, 2009 2:20 am

Re: Date comparision

Post 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....
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: Date comparision

Post by nite4000 »

Thanks I will give that a try
User avatar
genconv
Forum Commoner
Posts: 34
Joined: Sun Jul 05, 2009 9:27 am

Re: Date comparision

Post 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
Post Reply