Code: Select all
function getFirstSecond($days = 1, $time = 0)
{
// limitation of functions inside function creation
if($time == 0)
{
$time = time();
}
// Get the first second
$hours = date("G", $time);
$minutes = date("i", $time);
$seconds = date("s", $time);
$temp = $time;
$temp -= ($hours * 3600);
$temp -= ($minutes * 60);
$temp -= $seconds;
$today = $temp;
$first = $today;
$first -= ( ($days - 1) * 86400 );
return $first;
}Confusing? I thought so.
Example:
Code: Select all
print "Today's Start: " . date("r", getFirstSecond());
print "<br /><br />\n\n";
print "Past 3 Days (today counts as one): " . date("r", getFirstSecond(3));Real world use: lets say the column in table 'news' is the time() of creation of that row. In the query, just do:Today's Start: Thu, 8 Jul 2004 00:00:00 -0500
Past 3 Days (today counts as one): Tue, 6 Jul 2004 00:00:00 -0500
Code: Select all
SELECT * FROM `news` WHERE time >= '" . getFirstSecond(3) . "'