I'm creating a counter.

I want a timestamp where I can calculate if a time stamp is older than one hour, if so 
do X, if not do Y.

>Gabriel Guzman wrote:
>http://us4.php.net/time
>and
>http://www.mysql.com/doc/en/DATETIME.html

I have looked at both, especially http://www.mysql.com/doc/en/DATETIME.html
I got my fields to work. Did something stupid.

I'm using timestamp(14) which makes YYYYMMDDHHMMSS
therefore: 20030822033746 becomes:
2003-08-22-03:37:46 (I don't get a lot of sleep I guess :)  )

But this is a little difficult to extract a calculation.
In Javascript, however, it seems easier.

<script>
var expdate = new Date();

//################# Cookie Stuff
#####################################
// COOKIE EXPIRATION VARIABLES
// Set cookie to expire in 12 hours
// 1000 milliseconds (milliseconds per second)
// * 60 milliseconds (seconds per minute)
// * 60 milliseconds (minutes per hour)
// * 12 milliseconds (hours per day)
// * 1 milliseconds (days)
// -----------------
// = 12 hours

expdate.setTime (expdate.getTime() + (1000*60*60*12*1));
</script>

Is this the way to go in PHP? And how do I do it? Or is there a better way to have a 
timestamp?

John

-------snip this is the code I have so far -----

CREATE TABLE `counter` (
  `id` int(10) NOT NULL auto_increment,
  `IPAddress` varchar(100) NOT NULL default '',
  `RemoteHost` varchar(100) NOT NULL default '',
  `EntryDate` date NOT NULL default '0000-00-00',
  `MyTimeStamp` timestamp(14) NOT NULL,
  `MyTime` time NOT NULL default '00:00:00',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;

$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$getaddr = $_SERVER['REMOTE_ADDR'];
$gethost = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$EntryDate = date("Y-m-d");

$sql = "INSERT INTO $table (IPAddress,RemoteHost,EntryDate)
values('$getaddr','$gethost','$EntryDate')";

mysql_query($sql);

$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);

$result = mysql_query("SELECT * FROM $table", $myconnection);
$num_rows = mysql_num_rows($result);

echo "document.write(\"$num_rows visitors. \");";



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to