Compare DATETIME values???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Compare DATETIME values???

Post by seodevhead »

I have a column in a table that is of the DATETIME type. And whenever a record is inserted, that DATETIME column is assigned NOW() within the INSERT query.

I am now writing a script that should be able to determine if one record in this table was created before or after another record by using the DATETIME column.

For instance:

Code: Select all

if ($row1['date_entered'] > $row2['date_entered'])
Problem is, it doesn't seem to be working. It seems as though you can't compare DATETIME values (ie NOW() values) together. Can you? If not, what is a simple solution to this problem so I can compare two DATETIME values and see which is the earlier record. Thanks so much for your help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

seodevhead wrote:Can you?
Yes, you can.
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post by seodevhead »

Man thanks a ton feyd.. that makes things soooo much easier. After you told me that I can indeed compare DATETIME values... I took a closer look at one of the two queries and found that I was calling the DATE_FORMAT'ed column and not the original. Can't believe I didn't catch that on the first couple re-overlooks...Viola... it works. Thanks a ton buddy.
Post Reply