Getting specific date/time values in PHP
I have a cron task that logs a value in my database every 15 minutes so my database rows look so开发者_运维问答mething like this:
1, 100, 1311312600
1, 100, 1311313200
1, 90, 1311313800
etc.
The third field is a time() value.
Lets say the current time is 1:00PM on 07/22/2011. I want to see all of yesterdays values, so I need the following times for my SQL query.
07/22/2011 00:00:00
07/21/2011 00:00:00
How do I generate those values from the current time? Keep getting tripped up!
$yesterday_begin = strtotime('-1 day 12:00:00 AM');
$yesterday_end = strtotime('-1 day 11:59:59 PM');
Then
SELECT * FROM ... WHERE time_stamp BETWEEN $yesterday_begin AND $yesterday_end
select *
from logtable
where DATE(FROM_UNIXTIME(timestampfield)) = '2011/07/21'
$start = mktime(0, 0, 0, date('n') - 1, $day, date('Y');
$end = mktime(0, 0, 0, date('n'), $day, date('Y');
精彩评论