There is a MySQL table. How can I write entries (there is a timestamp
field) only for today, only for yesterday, only for a week, only for a month? Not in the last 24/48/168 hours, but in a day.
|
1 answer
SELECT * FROM `table` WHERE TIMESTAMPDIFF(DAY,FROM_UNIXTIME(time, '%Y-%m-%d %H:%i:%s'),NOW()) = 0
0 - the number of differences between days / months (DAY / MONTH).
There may be problems with the time zone, so MySQL will need to set the correct time zone corresponding to the data from the table.
- Either the skis do not go, or I do something wrong (zero line displays. There are no problems with the time zone, the correct MySQL server is set - Grigory Ponomarev
- oneShow your request. Which field contains the time? - Shevsky
- oneSo you have a timestamp type, so they would say right away, then everything is simpler and the FROM_UNIXTIME function is not needed. SELECT * FROM bug_table WHERE TIMESTAMPDIFF (DAY, datetime, NOW ()) = 0 ORDER BY datetime DESC - Shevsky
- oneI got used to everything that UNIX uses) - Shevsky
- oneOperators <and> have not been canceled. WHERE TIMESTAMPDIFF (DAY, datetime, NOW ()) <= 7 - Shevsky
|