Jump to content

Order by date


web_master

Recommended Posts

Hi,

 

<?php 
$QueryReturn = mysql_query('SELECT
	`ra_progbyday_year`,
	`ra_progbyday_month`,
	`ra_progbyday_day`
FROM
	`ra_progbyday`
ORDER BY
	??? ASC
');

?>

 

I got this query. `ra_progbyday_year`, `ra_progbyday_month` and `ra_progbyday_day` is an INT which is after reload for example: `ra_progbyday_year` = 2009, `ra_progbyday_month` = 04 and `ra_progbyday_day` = 04.

 

I got problem after ORDER BY, because I want to "ORDER" by date after reload. How can I list this 3 params like "date"?

 

- Or its enough to create column: `ra_progbyday_date` looks like: 20090404

 

Always will have a earlier date smaller nr that later date?

 

thnanx

T

 

 

Link to comment
Share on other sites

You can use a timestamp column to order things by their date. You can also order them using their month and year columns...

 

ORDER BY year DESC, month DESC

 

Haven't ever done it, but I'd imagine you can use any number of columns to order the data with... So try ORDER BY year DESC, month DESC, day DESC too if you want.

Link to comment
Share on other sites

- Or its enough to create column: `ra_progbyday_date` looks like: 20090404

Like revraz said, make a proper date column.  In the meanwhile, an "ORDER BY CONCAT_WS( '-', ra_progbyday_year, ra_progbyday_month, ra_progbyday_day) DESC" will work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.