Re: [PHP-DB] Date Select

2004-06-25 Thread jeffrey_n_Dyke



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 -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  '-mm-dd' and date_column
 '-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



RE: [PHP-DB] Date Select

2004-06-25 Thread Tom Chubb
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 25 June 2004 12:15
To: Tom Chubb
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
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 -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  '-mm-dd' and date_column
 '-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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Date SELECT with IF

2004-04-15 Thread Ignatius Reilly
SELECT
IF( B.Booking_End_Date != -00-00,
DATE_FORMAT( B.Booking_End_Date, %Y-%m-%d ),
N/A
) AS Booking_End_Date
FROM Bookings AS B, etc.

HTH
Ignatius
_
- Original Message -
From: Shaun [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 7:44 PM
Subject: [PHP-DB] Date SELECT with IF


 Hi,

 Is it possible to have a clause in a mysql SELECT statement? I would the
 query to display the date except where it equals the default 000-00-00 to
 display n/a or something similar.

 For example SELECT DATE_FORMAT(B.Booking_End_Date, \%Y-%m-%d\) AS
'Booking
 End Date' FROM Bookings (IF Booking_End_Date = '-00-00' DISPLAY
'n/a');

 I hope this illustrates what I am trying to achieve!

 Thanks for your help

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Date SELECT with IF

2004-04-15 Thread Marcjon Louwersheimer
try the WHERE clause.
SELECT name, address, phone, date FROM usertable WHERE date =
'-00-00'
And please, look at the mysql documentation, or at least the tutorial.
-- 
  Marcjon

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Date Select help

2002-09-23 Thread John Holmes

 Any one have any information on selecting a rake of dates from a mysql
 database?
 
 my current query reads.
 $result = mysql_query(SELECT * FROM CWC_Memory);
 
 I neeed to select where date is between todays date and todays date
+10.

SELECT * FROM CWC_Memory WHERE date_column BETWEEN NOW() AND NOW() +
INTERVAL 10 DAY

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php