Re: datetime manipulation >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. |