TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   converting to mysql date format (http://www.talkphp.com/absolute-beginners/111-converting-mysql-date-format.html)

harryhood 08-21-2005 01:16 AM

converting to mysql date format
 
I have a query I'm working on that pulls data from 2 columns, named 'Month' and 'Year'. I want to then combine these two columns to a date and order the results by that that date. I've been trying for a while with little success, so I'd be greatful for any help.

Here are the 2 methods I've been trying what I have tried:

1)
PHP Code:

"SELECT Month, Year FROM order ORDER BY str_to_date(CONCAT_WS('-',Year,Month,'01 00:00:00'),'%Y/%m/%d') asc" 

2)
PHP Code:

"SELECT Month, Year FROM order ORDER BY CAST(CONCAT_WS('-',Year,Month,'01') AS DATE) asc" 

Any suggestions or other ways to accomplish this?

thanks!

mikem 08-21-2005 03:57 AM

Try using two order statements.

PHP Code:

"SELECT Month, Year FROM order ORDER BY Year ASC, CAST(Month AS SIGNED) ASC"



All times are GMT. The time now is 03:50 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0