[PHP] RE: [PHP-DB] subtracting dates...

2003-08-02 Thread Ryan Marks
I found this code at Google's cached version of the manual for the
date() function:
http://216.239.37.104/search?q=cache:kq0aNfZeEp8J:www.php.net/date+diffe
rence+two+date+site:www.php.net&hl=en&ie=UTF-8

This code only returned the number of hours, minutes, and seconds
between the two points in time.  Now it returns years and days as well
as the left over time.  The script also used the mod operator (%) to
find the remaining days after determining the year and it would not
calculate correctly.  For example, if I compared yesterday, three years
ago(08-01-00) and today (08-02-03) at noon for both days, I would get a
difference of 3 years.  No I am using while loops subtracting whole
years to find the number of days that remain.  The same is true for
subtracting days, hours and minutes.

CODE:
 31536000){
$r -= 31536000;
}
$dd=floor($r / 86400);
while ($r > 86400){
$r -= 86400;
}
$hh=floor($r/3600);
if ($hh<=9) $hh="0".$hh;  //adds a leading 0 if less than 10
while ($r > 3600){
$r -= 3600;
}
$mm=floor($r/60);
if ($mm<=9) $mm="0".$mm; //adds a leading 0 if less than 10
while ($r > 60){
$r -= 60;
}
$ss=$r ;
if ($ss<=9) $ss="0".$ss; //adds a leading 0 if less than 10
$retval="$yy year(s), $dd day(s) $hh:$mm:$ss";
return $retval;
}

?>


OUTPUT:
19 year(s), 229 day(s) 05:22:01

Hope this helps,
Ryan Marks

-Original Message-
From: John Ryan [mailto:[EMAIL PROTECTED] 
Sent: Saturday, August 02, 2003 2:31 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] subtracting dates...


Hi,

In mySQL, I store dates as -MM-DD, a standard DATE type. It stores
users date of births. I need to calculate in a PHP script, the users age
from this DOB. I get a PHP date in the same format as the mySQL and
subtract, which returns the year rounded off. ie, it doesnt matter if
your birthdays in june of 1983 and the date is januray 2003, your age is
still returned as 20, when it should be 19.

Does anyone know how can i get the right age?



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


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



[PHP] RE: [PHP-DB] store whois requests

2003-09-16 Thread Ryan Marks
This is some code I already use... you may wish to change the way you
retrieve you whois data.
Ryan


Whois


Hostname:

$host";
//backwards tick marks will run this command on the server and echo's it
out to the screen
echo `whois $host`;
echo "";

//get the timestamp and ip
$timestamp = date("YmdHis");
$ip = getenv(REMOTE_ADDR);

//create your query
$query = "insert into whois_log (domain, timestamp, ip) values (\"$host\",
\"$timestamp\", \"$ip\")";

//run the query against the database with your variables for $server,
$username, and $password
$db = mysql_connect($server,$username,$password);
mysql_select_db("your_database",$db);
if (!$result = @mysql_query($query,$db)){
$error = mysql_error();
print("Error Processing Query: $error$query");
}
}
?>
document.theform.host.focus()



-Original Message-
From: IS [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 16, 2003 4:27 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [PHP-DB] store whois requests


I want to store whois requests including the ip address and date/time
stamp into a file or MySQL database (a database is what I prefer to use)
for monitoring the PHP whois script. Anybody an idea of how I could do
this? I'm a beginner in PHP so any help is welcome.

--IS

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

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