Jump to content

timestamp comparison

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
Hope you can help guys.

I am writing a php script and need to compare two timestamps to see if the new one is more than 15 minutes later than the last. Hope that makes sense.

$accessed is a value from a timestamp field in my database.

So I want to compare $accessed, if it is 15 mins more than $lastaccessed then I do something. If it is not I do something else.

make sense? Feel free to ask any questions

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
PHP: date_diff - Manual
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
adzeds

adzeds

    Newbie

  • Members
  • PipPip
  • 27 posts
Thanks.

Next problem is that I am trying to add 30 minutes to a datetime value taken from a database.

How can I do this? Here is my code:
		$a=0;
		while ($a < $num) {
		$Query = "SELECT * from analytics WHERE ipaddress = '" . $ipaddress[$a] . "'";
		$Result = mysql_query( $Query );
		$num2 = mysql_num_rows($Result);
		
			$b = 0;
			while ($b < $num2) {
			$accessed = mysql_result($Result,$b,"access_time");
						
			if ($lastaccessed = '') 
			{
			$lastaccessed = $accessed;
			$visitcount++;
			} 
			else 	{
                                $timeplus30 = ?;
				if($accessed > $timeplus30) 
				{
				$visitcount++;
				} else 
				{}
				}
			$b++;
			}
			
		$a++;
		}

Edited by WingedPanther, 17 December 2009 - 01:41 PM.
fix php tag


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
PHP: date_add - Manual
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog