Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id ADC5F476B43 for ; Fri, 5 Jul 2002 12:32:19 -0400 (EDT) Mailbox-Line: From hierophant@pcisys.net Fri Jul 5 12:32:19 2002 Received: from leo.pcisys.net (leo.pcisys.net [207.76.102.240]) by postgresql.org (Postfix) with ESMTP id 6F41F4769E8 for ; Fri, 5 Jul 2002 11:01:15 -0400 (EDT) Received: from [208.202.106.224] (moe1.meg106-224.cos.pcisys.net [208.202.106.224]) by leo.pcisys.net (8.12.1/8.12.1) via ESMTP id g65F1JTn029018 for ; Fri, 5 Jul 2002 09:01:19 -0600 (MDT) env-from (hierophant@pcisys.net) User-Agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.4 Date: Fri, 05 Jul 2002 09:01:18 -0600 Subject: Re: comparing dates From: Keary Suska To: Postgres-PHP Message-ID: In-Reply-To: <1025901211.1846.73.camel@Askr> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Spam-Status: No, hits=-4.2 required=5.0 tests=IN_REP_TO,X_NOT_PRESENT,DOUBLE_CAPSWORD version=2.30 X-Spam-Level: X-Archive-Number: 200207/9 X-Sequence-Number: 1311 on 7/5/02 2:33 PM, joseph@asti.dost.gov.ph purportedly said: > how do i compare the current date to a date field in my database > e.g. > $current_date = date('Y=m-d'); > $dbdate = pg_result($rsdate,0,"exam_date"); > if ($current_date>$dbdate) --THIS PART DOESNT WORK > echo "Today is not your exam date"; > TIA You have encountered what I consider one of the most annoying "features" if PHP. PHP is treating both values as strings, but when you do a comparison, PHP looks to see if the value looks like a number. If it does, it treats both as numbers, and discards any non-number portion. Because of this, chances are, you end up only comparing the years (everything after the first '-' is dropped). You have many options. Among them: 1) use stringcmp() 2) Make both into a number-looking string: date('Ymd') and str_replace( '-', '', $dbdate ) 3) convert to epochal time (seconds since epoch) using time() for current time, and strtotime to convert the db date. Note, however, that strtotime() cannot parse SQL dates because of the dashes. To get around this, you can: strtotime( str_replace( '-', '/', $dbdate ) ) Keary Suska Esoteritech, Inc. "Leveraging Open Source for a better Internet"