LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Mysql/PHP query problem with datetime field. (https://www.linuxquestions.org/questions/programming-9/mysql-php-query-problem-with-datetime-field-114468/)

Pcghost 11-10-2003 12:40 PM

Mysql/PHP query problem with datetime field.
 
I am trying to use a SELECT query to retrieve the earliest and the latest date/ time entries from my table. The field is a datetime (YYYY-MM-DD HH-MM-SS). I cannot find anything related to querying datetime in the MySQL manual.

What is the proper way to approach this?:confused:

When I do a $firstdate = mysql_query("SELECT MIN(datestamp) from seminar")
and then echo $firstdate I get the following
Resource id #5

markus1982 11-11-2003 02:15 AM

Quote:

$firstdate = mysql_query("SELECT MIN(datestamp) from seminar")
and then echo $firstdate I get the following
Resource id #5
Well actually when you use mysql_query you do not get the result stored in the $firstdate, instead you get a result set which can be used. For more information please consult PHP manual: mysql_query

Pcghost 11-11-2003 12:24 PM

As it turns out using MIN and MAX on a datetime field doesn't work the way I expected. It returns more than one record in decending order by value. I went with a mysql_fetch_array() and then set $i=mysql_num_rows($fetch) and did a mysql_data_seek($fetch, $i). Worked like a charm. Thanks anyway markus.


All times are GMT -5. The time now is 11:51 AM.