RE: [PHP-DB] Date Select

From: Date: Fri, 25 Jun 2004 11:17:40 +0000
Subject: RE: [PHP-DB] Date Select
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-db+get-34955@lists.php.net to get a copy of this message
Jeffrey, Thanks for this, I've just realised that it's always the same no of inserts, so perhaps I should just order by date then my previous sort field and then limit the result to 20? (It's all 20 results that I need displayed) Thanks, Tom -----Original Message----- From: jeffrey_n_Dyke@Keane.com [mailto:jeffrey_n_Dyke@Keane.com] Sent: 25 June 2004 12:15 To: Tom Chubb Cc: php-db@lists.php.net; php-general@lists.php.net Subject: Re: [PHP-DB] Date Select >How can I query a MySQL table to get the latest results from a date field? >Basically, I am inserting several records at a time at the end of each week. >I want to have a page that displays the results for the last week only. >The date format in the field is YYYY-MM-DD if you want the latest row - select * from table order by max(date_column) limit 1; if you want rows in a range of dates there are lots o ways, and instead of showing one or two, I'd suggest taking a look at the manual on dates http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html, and seeing what fits your needs best. Seems like you may want to look at BETWEEN And if you don't want to use those, you are always free to use select * from table where date_column < 'yyyy-mm-dd' and date_column < 'yyyy-mm-dd' order by date_col desc HTH Jeff -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#34955) next »