elpaisa Posted February 18, 2008 Share Posted February 18, 2008 Hi, I have an if statement tha is executed when the date in a DATE_TIME field in a database y is older than today heres is the code, $date = time(); if($user['exp_date'] >= $date) { $error[] = '<script language="javascript" type="text/javascript">alert(\'YOUR ACCOUNT HAS EXPIRED PLEASE RENEW YOUR MEMBERSHIP\');</script>'; } id doesn't work, the date time format in the database appears so: 2008-03-18 22:06:15, how do get the current time and compare it with the database field Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 19, 2008 Share Posted February 19, 2008 hello, you could convert both to a unix timestamp, should ork then: $date = time(); if(strtotime($user['exp_date']) >= $date) { $error[] = '<script language="javascript" type="text/javascript">alert(\'YOUR ACCOUNT HAS EXPIRED PLEASE RENEW YOUR MEMBERSHIP\');</script>'; } hope this helps, Quote Link to comment Share on other sites More sharing options...
mem0ri Posted February 19, 2008 Share Posted February 19, 2008 Just a general word of advice... I see lots of people trying to store text-dates with their applications...timestamps are almost always a better option. It's very easy to convert them back into "readable" format for display and they're very easy to compare/manipulate/etc. Quote Link to comment Share on other sites More sharing options...
elpaisa Posted February 19, 2008 Author Share Posted February 19, 2008 Can you give me an example, becouse i'm adding an interval of 1 month to the date with this code, and I don't know how to do it with unix timestamp: DATE_ADD(NOW(),INTERVAL 1 MONTH) Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 19, 2008 Share Posted February 19, 2008 could you give us an example full query your using the date_add statement? thanks, Quote Link to comment Share on other sites More sharing options...
chronister Posted February 19, 2008 Share Posted February 19, 2008 <?php $one_month_from_now = mktime(date('h'),date('i'),date('s'),date('m')+1,date('d'),date('y')); echo date('h:i:s m/d/y',$one_month_from_now); ?> here is how ya do one month from now. It looks messy, but it is actually really simple. it is just a combination of date() and mktime(). They can be a bit confusing at first but learn them, love them, and use them and date, time manipulation in PHP will be a breeze. Nate Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 He is using MySQL DateTime, not text. Just a general word of advice... I see lots of people trying to store text-dates with their applications...timestamps are almost always a better option. It's very easy to convert them back into "readable" format for display and they're very easy to compare/manipulate/etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.