On Saturday 06 September 2003 06:01, Darryl wrote: > 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 ? date() in php expects a unix timestamp. Dates in MySQL are NOT stored in unix timestamp format. You can perform the calculations directly in MySQL mysql manual > Tutorial Introduction > Date Calculations -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db ------------------------------------------ /* People with narrow minds usually have broad tongues. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php