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
elecktricity
Forum Contributor
Posts: 128 Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:
Post
by elecktricity » Fri Feb 10, 2006 2:40 pm
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
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 10, 2006 2:43 pm
Are you asking something? I'm confused.
elecktricity
Forum Contributor
Posts: 128 Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:
Post
by elecktricity » Fri Feb 10, 2006 2:57 pm
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
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Fri Feb 10, 2006 3:14 pm
You will need to use timestamps (
time() strtotime() etc.. ), either that or the mysql date functions
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 10, 2006 3:45 pm
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
elecktricity
Forum Contributor
Posts: 128 Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:
Post
by elecktricity » Fri Feb 10, 2006 9:36 pm
thanks it works now