date function
| From: | Darryl | Date: | Fri, 05 Sep 2003 22:01:51 +0000 |
| Subject: | date function | ||
| Groups: | php.db php.db | ||
| Request: | Send a blank email to php-db+get-30380@lists.php.net to get a copy of this message | ||
Greetings,
I have some php code that pulls from the mysql database. Here it is:
<?php
mysql_connect("wildcat.osborneindustries.com", "webuser",
"webpass");
$mymonth = date('n');
$cyear = date('Y');
$query = "SELECT name,hdate FROM emp2 where month(hdate)=$mymonth
order by hdate";
$result = mysql_db_query("iweb", $query);
if ($result) {
echo "<table align=center border=0 cellspacing=5 >";
while ($r = mysql_fetch_array($result)) {
$name = $r["name"];
$hyear = date('Y',$r["hdate"]);
$timein = $cyear - $hyear;
if ($timein > 0) {
echo
"<tr><td>$name</t><td>$timein</td><td>$cyear</td><td>$hyear</td></tr>";}
}
echo "</table>";
} else {
echo "No data.";
}
mysql_free_result($result); ?>
I'm trying to figure out years of employment based on hiredate. Its not
working as expected. $timein is always
1969. Date in the database is YYYY-MM-DD. What have I screwed up ?
thanks,
Darryl