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? 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. 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! 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) Link to comment https://forums.phpfreaks.com/topic/264746-simple-datetime-problem/#findComment-1357079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.