date or time or something

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
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

date or time or something

Post 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
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you asking something? I'm confused. :?
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

You will need to use timestamps ( time() strtotime() etc.. ), either that or the mysql date functions
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

thanks it works now
Post Reply