date time query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

date time query

Post by IGGt »

I'm picking up a datetime from a database and need to check whether it is greater than 30 minutes old.

e.g.

$date = 2010-11-24 14:12:55

If $date < (now - 30 minutes) then do this
else
do this

but I'm struggling to see how to do this, I can only find examples of static dates e.g. day1 - day2.

I'm sure this must be relatively straight forward.
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: date time query

Post by IGGt »

found a way to do it:

Code: Select all

	$half = time()-1800;
	$quart = time()-900;
	$con = strtotime($Aresult['ConnectedAt']);
	
	IF ($con < $half) {
		$col = $colour1;
	}elseif ($con < $quart) {
		$col = $colour3 ;
	}else{
		$col = $colour2;
	};
Post Reply