PDA

View Full Version : Last 24 hours


Sarge
03-22-2001, 05:02 PM
I am installing the hack for

Yesterdays Top Posters
And I want to make sure I got something correct

Is below the correct time to display for the last 24 hours?

Did I get the time right?

Sarge

$curTime = localtime();
$uts = time() - ($curTime[2]*3600 + $curTime[1]*60 + $curTime[0]);
$lts = $uts - (86401); // 3600 * 24 + 1 (to be completely honest about "yesterday")
unset($curTime);

03-22-2001, 07:35 PM
Considering I wrote that little piece of an algorithm you posted, in a way yes. That will calculate timestamps for the previous day, but don't confuse that with the last 24 hours. The last 24 hours would simple be the current timestamp - 86401.

What you have pasted will generate two timestamps: $lts (lower timestamp) will be equal to 00:00:00 the previous day, and $uts (upper timestamp) equal to 23:59:59 the previous day.

These timestamps can be used in a MySQL SELECT statement for comparrison with the dateline member or such things as posts, threads, polls.

03-22-2001, 08:03 PM
It's more accurate to use mktime (http://php.net/manual/en/function.mktime.php)

$24hrsback = mktime (date("H")-24, date("i"), date("s"), date("m"), date("d"), date("Y"));
$now = time();

03-23-2001, 01:31 AM
How is it more accurate? The current timestamp is the current timestamp.

Personally I don't like making tons of function calls when none are needed. Inside your call to mktime() you are calling date 6 times. Sure with today's processors the overhead of a function call is not much, but then lets add in the fact that PHP isn't compiled code... I haven't looked at the source yet, but I bet every call to a function creates a new local scope for the function in addition to any memory used inside the date function. It also uses formatted strings. All that will add up to more then the simple mathmatical operations on array elements.

I'm not trying to start a coding debate. The simple point is, run my code 1e9 times and run code with extra function calls and I don't think you can argue which will be faster. I don't like wasteing CPU cycles or memory where I don't have to.

03-23-2001, 10:31 AM
What have i to do, if I want to install this hack?

Is there a hack to show yesterday new posts, threads an new members? Hope someone could help me :)

Have a nice day
Tommy