Re: date function

From: Date: Fri, 05 Sep 2003 23:07:22 +0000
Subject: Re: date function
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-30382@lists.php.net to get a copy of this message
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. */

« previous php.db (#30382) next »