pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: comparing dates
3+ messages / 3 participants
[nested] [flat]

* comparing dates
@ 2002-07-05 20:33 Joseph Syjuco <joseph@asti.dost.gov.ph>
  2002-07-05 08:33 ` Re: comparing dates Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2002-07-05 15:01 ` Re: comparing dates Keary Suska <hierophant@pcisys.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Joseph Syjuco @ 2002-07-05 20:33 UTC (permalink / raw)
  To: pgsql-php

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







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: comparing dates
  2002-07-05 20:33 comparing dates Joseph Syjuco <joseph@asti.dost.gov.ph>
@ 2002-07-05 08:33 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  1 sibling, 0 replies; 3+ messages in thread

From: Christopher Kings-Lynne @ 2002-07-05 08:33 UTC (permalink / raw)
  To: Joseph Syjuco <joseph@asti.dost.gov.ph>; pgsql-php

Use mktime to convert them both to unix timestamps and then compare them as
integers, or compare them in the database directly.

Chris


> -----Original Message-----
> From: pgsql-php-owner@postgresql.org
> [mailto:pgsql-php-owner@postgresql.org]On Behalf Of Joseph Syjuco
> Sent: Saturday, 6 July 2002 4:33 AM
> To: PHP-PGSQL
> Subject: [PHP] comparing dates
>
>
> 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
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: comparing dates
  2002-07-05 20:33 comparing dates Joseph Syjuco <joseph@asti.dost.gov.ph>
@ 2002-07-05 15:01 ` Keary Suska <hierophant@pcisys.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Keary Suska @ 2002-07-05 15:01 UTC (permalink / raw)
  To: pgsql-php

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"






^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-07-05 20:33 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-05 20:33 comparing dates Joseph Syjuco <joseph@asti.dost.gov.ph>
2002-07-05 08:33 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-07-05 15:01 ` Keary Suska <hierophant@pcisys.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox