Page 1 of 1
date or time or something
Posted: Fri Feb 10, 2006 2:40 pm
by elecktricity
I have a database one of the cols is 'premium' basicially its a spot if there premium or not, premium only lasts a month, so im thinking about putting it in as a date like 02/10/06 so 30 days from then 03/12/06 (I think) it would expire, this goes on pages like:
Code: Select all
<?PHP
$date = $row['premium'];
$date2 = date(m/d/Y);
if ($date<=$date2) }
//do something
}
else {
//do something else
}
?>
Posted: Fri Feb 10, 2006 2:43 pm
by feyd
Are you asking something? I'm confused.

Posted: Fri Feb 10, 2006 2:57 pm
by elecktricity
yea the dates are just like
02/10/06 and the such, I dont belive you can compare them by using greater than or less than signs cause it has the / in them
Posted: Fri Feb 10, 2006 3:14 pm
by josh
You will need to use timestamps (
time() strtotime() etc.. ), either that or the mysql date functions
Posted: Fri Feb 10, 2006 3:45 pm
by feyd
You actually can compared them if they are in a uniform dimension:
Code: Select all
[feyd@home]>php -r "$a = strtotime('last monday'); $b = time(); echo date('Y/m/d',$a).'<'.date('Y/m/d',$b).'?'.var_export($a<$b,true);"
2006/02/06<2006/02/10?true
[feyd@home]>php -r "$a = strtotime('last monday'); $b = time(); echo date('m/d/Y',$a).'<'.date('m/d/Y',$b).'?'.var_export($a<$b,true);"
02/06/2006<02/10/2006?true
[feyd@home]>php -r "$a = strtotime('last monday'); $b = time(); echo date('m/d/Y',$a).'>'.date('m/d/Y',$b).'?'.var_export($a>$b,true);"
02/06/2006>02/10/2006?false
Posted: Fri Feb 10, 2006 9:36 pm
by elecktricity
thanks it works now