SocomNegotiator Posted May 27, 2007 Share Posted May 27, 2007 Well I am trying to take the current date - 1 day to check my Database for users who joined at least 1 day ago form the current date....here is my code.... $cur_return = date("Y-m-d H:i:s"); $date = explode('-', $cur_return); $user_date = date("Y-m-d H:i:s", mktime(0,0,0, $date[1], $date[2]-1, $date[0])); // So $user_date is the current date - 1 day.....now I need to search the DB for any users who's join date is greater than this. For instance, the date is May 26th well with this would make it 2007-05-25 00:00:00. $RecentUser = 'SELECT username FROM ls_users WHERE date_joined > '.$user_date; $ResultUser = mysql_query($RecentUser); $getrow = mysql_fetch_array($ResultUser); echo '<li><a href="#"><img src="{skin}files/r1.jpg" alt="Username"><span>'.$getrow['username'].'</span></a></li>'; now for some odd reason this does not work....I know that the current date - 1 day works, because I did an echo on $user_date and it was " 2007-05-25 00:00:00" which is in the correct format as the date_joined field in the database. Any help would be much appreciated thanks.... Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/ Share on other sites More sharing options...
dustinnoe Posted May 27, 2007 Share Posted May 27, 2007 <?php $one_day_ago = mktime(0,0,0,0,-1, 0); ?> Seems a little easier to go this route. Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/#findComment-262438 Share on other sites More sharing options...
kenrbnsn Posted May 27, 2007 Share Posted May 27, 2007 I like to use the strtotime() function. <?php $one_day_ago = date('Y-m-d',strtotime('-1 day')); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/#findComment-262439 Share on other sites More sharing options...
dustinnoe Posted May 27, 2007 Share Posted May 27, 2007 I like to use the strtotime() function. <?php $one_day_ago = date('Y-m-d',strtotime('-1 day')); ?> Ken That's a good way. You don't have to remember which parameter in mktime() is the day. I always have to reference the manual. Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/#findComment-262443 Share on other sites More sharing options...
Diego17 Posted May 27, 2007 Share Posted May 27, 2007 Mysql can perform that without the help of php Curdate() - Interval 1 day Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/#findComment-262484 Share on other sites More sharing options...
SocomNegotiator Posted May 27, 2007 Author Share Posted May 27, 2007 Mysql can perform that without the help of php Curdate() - Interval 1 day This worked like a charm.....thanks Quote Link to comment https://forums.phpfreaks.com/topic/53125-solved-php-current-date-1-dayused-for-a-mysql-query/#findComment-262702 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.