October 13, 20188 yr Hello everyone, Currently creating a my orders page for the shop on my website. I learned the hard way that you shouldn't use just 1 field for the date but need separates for day month and year because when you have 01/01/2018 it doesn't work order after the /. So this seems to work: SELECT *, (ORDERDAY+ORDERMONTH+ORDERYEAR) AS total FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY total DESC Is the code above the correct way to order them? Edit: I think this did the trick: SELECT *, (DATE(ORDERYEAR)+DATE(ORDERMONTH)+DATE(ORDERDAY)) AS date FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY date DESC Edited October 13, 20188 yr by ChubbyKakert
October 14, 20188 yr Author There still seems to be something wrong. This is the code: $getordersquery = $db->query("SELECT *, (DATE(ORDERYEAR)+DATE(ORDERMONTH)+DATE(ORDERDAY)) AS date FROM SHOPORDERS WHERE USERID = '$dbget_id' ORDER BY date ASC"); I tried both DESC and ASC but the results are the same. What am i doing wrong? Please don't pay attention to the date format. There should be only a yesterday or today on the date but i have the full date for testing purposes. I know that i could use the Order ID to order them but i think doing it on date would be better and useful cause i will need it for the forums too etc.
October 15, 20188 yr It's because of the date format, you need it to become year-month-day hour:minutes:seconds. Not sure how far through you are but you should be storing the correct date and time format in the database as a DATE/TIME Data Type. Then you can make simple SQL requests where date is between two dates, show time in the persons current timezone and more.
Create an account or sign in to comment