Click to See Complete Forum and Search --> : How to make Date Condtion?


saturngod
12-18-2006, 08:06 AM
I retrive date from MYSQL and check with current date for account expire.
I write

if($today<$expire)
echo "Work";
else
echo "Expire";

$today is today date and $expire is data from MYSQL.But not work.It always show Work.How to make date condition?

Thank

NightShift58
12-18-2006, 08:10 AM
What does $today look like?
What does $expire look like?

My guess is that even though - to you - they are just dates, their internal formats are quite different.

saturngod
12-18-2006, 08:14 AM
$today=date('Y-M-d');
$expire='2007-12-18' //is from MYSQL

Sorry i not in home so I don't have source code now,I from cyber cafe.I will wirte code detail when I come bake home.

NightShift58
12-18-2006, 08:19 AM
That's your problem then...

date("Y-M-d") ==> 2006-Dec-18
date("Y-m-d") ==> 2006-12-18

saturngod
12-18-2006, 10:52 AM
function expiredate($id)
{
$query="SELECT id,expire FROM ads WHERE id=".$id;
$result=@mysql_query($query);
while($row=mysql_fetch_array($result))
{
$expiredate=$row[1];
}
$tody=date("Y-m-d");
if ($tody<$expire)
{
return true;
}
else return false;

}

It always return ture.Doesn't not work.

NightShift58
12-18-2006, 11:01 AM
(1) Where does $expire come from?
(2) Just to be safe, you probably want to add " LIMIT 1 " to your $query

balloonbuffoon
12-18-2006, 01:11 PM
I would compare the dates based on their timestamps, using time() (http://php.net/time) to get the current timestamp, and strtotime() (http://php.net/strtotime/) to convert the time coming from the database:
function expiredate($id) {
$query="SELECT expire FROM ads WHERE id=".$id;
$result=@mysql_query($query);
$expiredate=mysql_result($result,0,"expire");
$tody=time();
if ($tody<strtotime($expire)) {
return true;
}
else return false;
}--Steve

NightShift58
12-18-2006, 01:14 PM
The question still remains: where does $expire come from?

I can see $expiredate but I see no other reference to $expire.

Is perhaps the wrong variable being used to compare dates?

I don't think that doing two conversions from date to time will help at all unless the proper variables are being used at the right time.

saturngod
12-19-2006, 11:38 AM
Thank all! I can solve it...

saturngod
12-19-2006, 11:56 AM
The question still remains: where does $expire come from?

I can see $expiredate but I see no other reference to $expire.

Is perhaps the wrong variable being used to compare dates?

I don't think that doing two conversions from date to time will help at all unless the proper variables are being used at the right time.

$expire .It's my false.It's $expiredate but not work.Now I finish it and thank you all for help.

lyndon
11-23-2007, 03:02 AM
Hi, we hve same situation, can you share me your source code on expire date .. please.. thanks

knowj
11-23-2007, 03:18 AM
Why dont you just check everything on the SQL side?

MySQL is more than capable of checking if a date is greater than, less than or equal to. You can also check against todays date et...

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html