Jump to content

[SOLVED] ORDER BY date AND time


coolphpdude

Recommended Posts

Hi there,

 

im sure this will be a quick one for most.

 

I'm trying to order my memo's to students by date and time posted, i have the following query but for some reason my results dont seem to be output by date and time correctly.

 


SELECT * FROM memo WHERE student='$student' ORDER BY memo_time AND memo_date DESC 

 

outputs the following...

 

Memo ID      Subject              Date & Time 

10              revision class        2008-08-07 20:40 

11              hand in date        2008-08-08 10:31 

12              review                2008-08-08 11:04 

13              review                2008-08-08 11:05 

14              review                2008-08-08 11:05 

15              review                2008-08-08 11:05 

16              review                2008-08-08 11:05 

 

Any idea?

 

Link to comment
https://forums.phpfreaks.com/topic/118761-solved-order-by-date-and-time/
Share on other sites

Why don't you save your table date and time in one single column?

the layout is identical to what you need.

set the column type: datetime

after that, if you need only the date, from that value, you call function date()

example

 <?php
// Assuming today is: March 10th, 2001, 5:16:18 pm
$getdate="2001-03-10 17:16";

$today = date("F j, Y, g:i a", $date);                 // March 10, 2001, 5:16 pm
$today = date("m.d.y", $date);                         // 03.10.01
$today = date("j, n, Y", $date);                       // 10, 3, 2001
$today = date("Ymd", $date);                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day z ', $date);  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.', $date);   // It is the 10th day.
$today = date("D M j G:i:s T Y", $date);               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h', $date);     // 17:03:17 m is month
$today = date("H:i:s", $date);                         // 17:16:17
?>

you can find a more complete example on www.php.net/date

 

You are using ,

 

SELECT * FROM memo WHERE student='$student' ORDER BY memo_time AND memo_date DESC

 

in here order only effect to the memo_date. Therefore i think you have to use.,,

 

SELECT * FROM memo WHERE student='$student' ORDER BY memo_time DESC, memo_date DESC

 

Try this!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.