By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,394 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,394 IT Pros & Developers. It's quick & easy.

Compare two string dates using an IF statement?

P: n/a
Hi,

How do I compare two date stored within a database with datatype
'date'?

The dates are stored within a PostgreSQL database table in the format
"Y-m-d".

Cheers

Burnsy

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
*** bi******@yahoo.co.uk wrote/escribió (24 May 2005 04:40:01 -0700):
The dates are stored within a PostgreSQL database table in the format
"Y-m-d".


Find out whether PostgreSQL has a function to return dates as Unix
timestamp. Afterwards, all you need is a regular < comparison.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2

P: n/a
In PHP strtotime() will also recognize the Y-m-d format. So, take
whatever you get from your database query, and call something like:

$dateFromDB = '2005-2-20'; //would come from DB
$timestamp = strtotime($dateFromDB);

$timestamp now contains a Unix timestamp (in PHP, an integer). If
you've got two of them, the comparison is the same as comparing any
other two numbers as Alvaro points out.

Jul 17 '05 #3

P: n/a
bi******@yahoo.co.uk wrote:
How do I compare two date stored within a database with datatype
'date'?

The dates are stored within a PostgreSQL database table in the format
"Y-m-d".


If you get this as string from the db you just can simply use strcmp():
"2005-05-25" < "2005-05-26"
Jul 17 '05 #4

P: n/a
bi******@yahoo.co.uk wrote:
How do I compare two date stored within a database with datatype
'date'?

<snip>

<news:11*********************@f14g2000cwb.googlegr oups.com> or
<http://groups-beta.google.com/group/comp.lang.php/msg/6321c4a4b851f4e0>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.