Solved

advanced time question.

Posted on 2004-10-05
8
226 Views
Last Modified: 2008-02-01
Hi i need som kind of function to do my work. In my mysqltable i have a date ex 2004-10-05 14:00 and i need to check if it have gone ex 24hour. If you read my code i have post here you will propobly understand what i mean. And if it have gone more then 24h the script will not stop at
} if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
I hope someone can help me with this question. I think it's kind a hard.



function ratiocheck()
{
      global $_GET;
      
      $ratio = 0.1;
      $gigs = 1;

      $hash = checkhash($_GET['info_hash']);
      
      $result = mysql_query("SELECT * FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
      while ($gtim = mysql_fetch_array($result))
      {
            $p_time = $gtim['p_time'];
         // $p_time is the time (2004-10-05 16:00)
      }
      
      $p_time = $elapsed;
      // ratio
      if ($ratio < 0.5) {
            $wait = 24;
      } elseif ($ratio < 0.8 || $gigs < 6) {
            $wait = 12;
      } elseif ($ratio < 0.9 || $gigs < 10) {
            $wait = 6;
      } elseif ($ratio < 1.0 || $gigs > 15) {
            $wait = 0;
      } if ($elapsed < $wait) {
            bterror("Not authorized (" . ($wait - $elapsed) . "h) - READ THE FAQ!");
            exit();
      }
}
//############################# SLUT #######################
0
Comment
Question by:stromberg10
8 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 50 total points
ID: 12229068
You are not setting the $elapsed variable anywhere.  Maybe this line:

$p_time = $elapsed;

Should be this:

$elapsed = $p_time;

Or, you could remove the line altogether, and then make the final if statement look like this:

if ($p_time < $wait) {
          bterror("Not authorized (" . ($wait - $p_time) . "h) - READ THE FAQ!");
          exit();
}


Any reason you're screaming SLUT at the bottom of the code?
0
 
LVL 27

Assisted Solution

by:Diablo84
Diablo84 earned 50 total points
ID: 12230927
As a side note you do not need this line

global $_GET;

$_GET is a super global, you can access it in the function anyway
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 50 total points
ID: 12231993
You could use strtotime() to change the '2004-01-01 10:10' into a unix timestamp. You could then match this with the result from mktime() and look if the 24 hours have past:

if(mktime() < strtotime($p_date)  + $wait)
{
  //still in waiting periode
}
else
{
  //waiting period has passed.
}

Or I might understand your question incorrectly.

Regards

-r-
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Assisted Solution

by:aot2002
aot2002 earned 50 total points
ID: 12233871
mysql> SELECT DATE_ADD('1999-01-01', INTERVAL 1 DAY);
        -> '1999-01-02'



http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html
0
 
LVL 14

Assisted Solution

by:ThG
ThG earned 50 total points
ID: 12238396

I think Roonan's answer should work. If you want a MySQL solution here it is:

mysql> select if(now() > date_add('2004-10-03 13:22:00', INTERVAL 1 DAY), 1, 0);

     $result = mysql_query("SELECT *,IF(NOW() > date_add(p_time, INTERVAL 1 DAY), 1, 0) AS elapsed FROM torrents WHERE p_hash = '$hash'")OR die (bterror("error in mysql"));
          $p_time = $gtim['p_time'];
        // $p_time is the time (2004-10-05 16:00)
        $elapsed = $gtim['elapsed'];
         // $elapsed is 1 if 24 hours elapsed, otherwise 0
     }
     
   
0
 
LVL 1

Expert Comment

by:aot2002
ID: 12238685
thanks ThG

i just wanted to make sure he had both options !
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 58
How to change the link of an image using md5 in php ? 3 47
Decrypt string by php 7 47
How to set the Tinymce Editor image path 4 22
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question