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 Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/ 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, Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-470158 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. Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-470163 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) Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-470660 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, Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-471002 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 Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-471135 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. Link to comment https://forums.phpfreaks.com/topic/91776-compare-date_time-field-with-current-date/#findComment-471140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.