This is a discussion on datetime manipulation within the MySQL forums, part of the Database Server Software category; --> I have an id in mySQL server with format dateStart DATETIME (// YYYY- MM-DD HH:MM:SS) Now I want to ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have an id in mySQL server with format dateStart DATETIME (// YYYY- MM-DD HH:MM:SS) Now I want to sort the table by today and 1 week starting from now. $today = date("Y-m-d h:i:s"); I am not sure how to achieve that, any help? thank you. |
| |||
| >I have an id in mySQL server with format dateStart DATETIME (// YYYY- >MM-DD HH:MM:SS) > >Now I want to sort the table by today and 1 week starting from now. >$today = date("Y-m-d h:i:s"); What does it mean to sort by two different things? >I am not sure how to achieve that, any help? thank you. If you want to fetch records between today and 1 week starting from now, you could do (this uses the MySQL server time, not the time on the PHP server): SELECT * FROM table WHERE dateStart >= now() AND dateStart < dateadd(now(),7); If you also want to order by dateStart, you can add: ORDER BY dateStart SQL queries sort the output, not the table. If you don't specify ORDER BY, you have no complaint about the order of the rows in the result set. |
| |||
| Slickuser wrote: > I have an id in mySQL server with format dateStart DATETIME (// YYYY- > MM-DD HH:MM:SS) > > Now I want to sort the table by today and 1 week starting from now. > $today = date("Y-m-d h:i:s"); > > I am not sure how to achieve that, any help? thank you. google mysql date and read the docs. they are replete with examples on date time manipulation. |
| |||
| On 4 Mar, 02:43, gordonb.9z...@burditt.org (Gordon Burditt) wrote: > SQL queries sort the output, not the table. Not always totally true. Sometimes a table index will be used to supply the data in the correct order for the output. |
| ||||
| >> SQL queries sort the output, not the table. >Not always totally true. Sometimes a table index will be used to >supply the data in the correct order for the output. That sorts the output, not the table. If you said "sometimes a table index will be used to physically order the data in the table" and could demonstrate portable SQL to do that, OK. But there's no SQL to retrieve the table in physical order. |