Jakebert Posted June 25, 2012 Share Posted June 25, 2012 I'm trying to grab the current time of the user's computer and compare it to two date times in the database. The dates in the database are stored in this format: "2012-06-24 00:00:00". This is the code I have: //today's date $date = new DateTime(); // since that comes back in UNIX format, change it so it matches the DB format $now = date_format($date, 'Y-m-d H:i:s'); while ($output = mysqli_fetch_assoc($info)) { //let's check the open and close dates if (($now>$output['open_date']) || ($now<$output['close_date'])) {echo "There are no ballots for you at this time.";} else { echo $output['display_name']; echo "<br />"; echo $output['open_date']; echo "<br />"; } } } There's got to be a problem with the comparison line... I just can't tell what it is. Also where can I move the "there are not ballots for you at this time" so that it doesn't echo for every ballot? Quote Link to comment https://forums.phpfreaks.com/topic/264746-simple-datetime-problem/ Share on other sites More sharing options...
scootstah Posted June 25, 2012 Share Posted June 25, 2012 You can't get the client's time with just PHP. DateTime (and other date functions) use the server's date/time. Quote Link to comment https://forums.phpfreaks.com/topic/264746-simple-datetime-problem/#findComment-1356843 Share on other sites More sharing options...
debian23 Posted June 26, 2012 Share Posted June 26, 2012 in database the column must be ,,datetime,, and in php you must use function date("Y-m-d H-i-s"); Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/264746-simple-datetime-problem/#findComment-1357042 Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2012 Share Posted June 26, 2012 You haven't really described the actual problem, but I have a feeling this is what you're trying to do. SELECT field FROM table WHERE CURDATE() BETWEEN DATE(open_date) AND DATE(close_date) Quote Link to comment https://forums.phpfreaks.com/topic/264746-simple-datetime-problem/#findComment-1357079 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.