Jump to content

simple DateTime problem


Jakebert

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.