LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-10-2003, 12:40 PM   #1
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Real Washington
Distribution: Ubuntu, Debian, SuSE, UnSlung, Android
Posts: 1,819

Rep: Reputation: 46
Question 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?

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

Last edited by Pcghost; 11-10-2003 at 12:47 PM.
 
Old 11-11-2003, 02:15 AM   #2
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 45
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
 
Old 11-11-2003, 12:24 PM   #3
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Real Washington
Distribution: Ubuntu, Debian, SuSE, UnSlung, Android
Posts: 1,819

Original Poster
Rep: Reputation: 46
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php mcrypt cookie - mysql query lemack Linux - Security 3 02-09-2005 09:21 AM
php/,mysql problem: can't query JJX Linux - General 4 01-06-2005 05:10 PM
php: Why Can't I Query Mysql DB?? flamesrock Programming 7 11-16-2004 12:36 AM
php mysql variable arguments in query. ldp Linux - Software 0 10-26-2004 07:56 AM
PHP MySQL Query Question vi0lat0r Programming 1 07-15-2004 05:02 AM


All times are GMT -5. The time now is 07:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration