-2

I'm using a WordPress plugin that re-sets its stats every 7 days using the following line of code:

$keep_time = 60*60*24*7; // 7 days for now (TODO: admin setting)

Could someone help me to modify the code to re-set the stats every 6 hours or every other day? I did try to try to change the 7 to 1 but it doesn't work. Probably the solution is very simple, but unfortunately I'm not a PHP programmer.

Thanks everyone for answering my question, wanted to give a vote but I don't have enough 'reputation'

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • `keep_time` is in seconds, so 60 * 60 * 6 (60 seconds in minute, 60 minutes in one hour and 6 hours). no need to php programmer to see it ) – Cheery Oct 03 '14 at 02:00

3 Answers3

1

For 6 hours use:

$keep_time = 60*60*6;

For 2 days use:

$keep_time = 60*60*24*2;

The value is in seconds. 60*60 is the number of seconds in an hour. Then you multiply by the number of hours you want. If you want multiple days, you multiply by 24 hours in a day, and then the number of days.

Barmar
  • 741,623
  • 53
  • 500
  • 612
1

I like DateTime() and DateInterval() for this. Not only is it clearer but it handles daylight savings time and leap years as well as those pesky last days of the month.

7 Days:

$start_time = new DateTime(); // "now" as an example
$keep_time = new DateInterval('P7D'); // 7 days
$start_time->add($keep_time);
echo $start_time->format('Y-m-d');

6 Hours

$start_time = new DateTime(); // "now" as an example
$keep_time = new DateInterval('PT6H'); // 6 hours
$start_time->add($keep_time);
echo $start_time->format('Y-m-d');
John Conde
  • 217,595
  • 99
  • 455
  • 496
0
 $keep_time = 60(sec)*60(min)*24(hours)*7(days);

you need to do

 $keep_time = 60*60*6;
Snowman
  • 47
  • 6