thefollower Posted August 21, 2007 Share Posted August 21, 2007 I have a code which loads up the register date of the user compares that date to the the very instant of now, and then i have an if statement to do "if older than X amount of days - do this" But its not working This is what i have: //get register date and now date $GetDate = mysql_query("SELECT DATEDIFF(NOW(), RegisterDate) AS DaysOld FROM userregistration WHERE UserID='{$_SESSION['Current_User']}'") or die(mysql_error()); $daysoldrow = mysql_fetch_assoc($GetDate); Then the if statement: if ($daysoldrow['DaysOld'] > 200) {code blah blah; } Any one see the problem i made ? Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/ Share on other sites More sharing options...
trq Posted August 21, 2007 Share Posted August 21, 2007 What is the output of... <?php echo "<pre>"; print_r($daysoldrow); echo "</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330426 Share on other sites More sharing options...
thefollower Posted August 21, 2007 Author Share Posted August 21, 2007 Array ( [DaysOld] => 0 ) that was the result Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330427 Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 DATEDIFF() will only compare days, not time. If the dates in RegisterDate are the same DAY as today (even with different times) it won't work. It will probably return 0 if this is the case. Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330430 Share on other sites More sharing options...
thefollower Posted August 21, 2007 Author Share Posted August 21, 2007 i have found a problem. you are correct how ever i knew that already. but the problem is with my table field. I edited the field "resgisterdate" and set the year to 2004 from 2007. How ever when i save it resets back to how it was. No idea how its doing that. Any thoughts? Im thinking its field setting related but i dont know much about the settings of time stamps in tables. Argh its sorted now. It was my field settings i had "on update" attribute on . That was clumsy of me ! thanks for the help though guys. I wldnt of spotted it without you guys Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330432 Share on other sites More sharing options...
trq Posted August 21, 2007 Share Posted August 21, 2007 What data type is the field? Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330433 Share on other sites More sharing options...
thefollower Posted August 21, 2007 Author Share Posted August 21, 2007 time stamp data type. that was the format : 2004-08-22 00:27:23 got it working though as mentioned above ^ thanks thorpe and lemmin Quote Link to comment https://forums.phpfreaks.com/topic/66070-solved-my-comparison-is-not-working/#findComment-330435 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.