I would like to retrive a TODAY'S data from the database, but I don't know how to do it. I would actually want to get the data from NOT the past 24 hours, I just want today's data (so based on the actual server time).
I would also like to get data which was yesterday. Can anyone help me how to do it?
Sample code:
"SELECT id FROM folk WHERE time = ???"
Thank you in advance!
I think you are looking for this:
"SELECT id FROM folk WHERE DATE(time) = CURDATE()"
time must be a field in you table that holds a reference to the row.
update
To get yesterdays additions:
"SELECT id FROM folk WHERE DATE(time) = CURDATE() - 1"
update 2
To get all additions this month:
"SELECT id FROM folk
WHERE MONTH(time) = MONTH(NOW()) AND YEAR(time) = YEAR(NOW())"
reference: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
SELECT id FROM folk WHERE DATE(time) = DATE(NOW());
SELECT id FROM folk WHERE DATE(time) = DATE(DATE_SUB(NOW(), INTERVAL 1 DAY));
provided that 'time' has a proper date-time type
As you are using timestamp:
"SELECT id FROM folk WHERE time >= ".mktime(0, 0, 0)
That will select all data since beginning today.
If you want to get all date not for today, you would do
"SELECT id FROM folk WHERE time < ".mktime(0, 0, 0)
To select data from yesterday, you would do:
"SELECT id FROM folk WHERE time < ".mktime(0, 0, 0)." AND time >= ".mktime(0, 0, 0, date('m'), date('d')-1, date('Y'))
If you were to use DATETIME, just for reference, it would be something like:
"SELECT id FROM folk WHERE time >= '".date('Y-m-d').' 00:00:00."'"
Try something like this>>
SELECT id from folk WHERE DAY( date ) = EXTRACT(DAY from (NOW() - inTERVAL
1 DAY ) )
Refer this link http://www.webmasterworld.com/forum112/278.htm
Get current date by using something like following query
SELECT *
FROM your_table_name
WHERE DAY('.$colum_name.') = DAY("2018-05-02")';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.