Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member Noteleklabs's Avatar
    Join Date
    Jun 2012
    Location
    NC
    Posts
    217
    Member #
    31890
    Liked
    28 times

    Angry Time Filtering Being Diffacult

    Hello All!
    I have been having some trouble filtering my custom timestamps for a graph, and was wondering if anyone could help me figure out why.

    PHP Code:
    function getTicketResponseTime($department$hours){
         
    // Create connection    $con= REDACTED
        
    $query REDACTED
        $result 
    mysqli_query($con,$query);
        
    $num mysqli_num_rows($result);
        
    $filteredResults[] = null;
        while(
    $row mysqli_fetch_array($result)){
            
    //Create a timestamp for the ticket, then deconstruct that aswell
            
    $odate split("#",$row['timestamp']);
             
    $ticketTimestamp split("-",$odate[0])[2]."-".split("-",$odate[0])[1]."-".split("-",$odate[0])[0]." ".$odate[1]; //reformatting timestamp to d-m-y h:m:s
            
    if($hours == 0){
                if(
    strtotime($ticketTimestamp) <= strtotime('4 hours') && $row['department'] == $department){
                    
    array_push($filteredResults$row['firstresponsetime']);
                }        
             }else{
                if(
    strtotime($ticketTimestamp) <= strtotime($hours.' hours') && $row['department'] == $department){
                    
    array_push($filteredResults$row['firstresponsetime']);
                }
            }
        }
        
    //Average the numbers in the array, and convert to hours
        
    return round((((array_sum($filteredResults)/count($filteredResults))/60)/60)/602);

    The value hour is supposed to be the offset for the graph (8 hours back, 12 hours back, etc)

    Right now tweaking either shows the results for only now, or shows the same result regardless of hour. I've been working on this for five days now....
    Hey you! Go make something!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    To answer your question, see this:
    PHP: strtotime - Manual

    You need to specify + or - hours ...
    strtotime('+4 hours')

    But I sometimes get errors when I use that, and it has to do with formats as noted on the php.net manual:

    Note:

    Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
    To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD)
    Read contributor notes in the manual for discussions about calculation errors due to date/time formatting.



    IF YOU WISH TO FORCE YOUR WEBHOST SERVER TO USE YOUR TIMEZONE:

    You need to set your timezone, or it will be using your server's timezone,
    which may not be on the East Coast. Your time calculations could be off by hours.

    Put this at the top of your script for any script that uses time and date functions:
    <?php
    date_default_timezone_set('America/New_York');

    You live in NC, so the identifier for you (Eastern Time) is "America/New_York".



    IF YOU CHOOSE TO USE INTEGER MATH FOR TIMESTAMPS, READ ON ...

    As the manual mentioned, the most accurate method to create a timestamp
    from human readable is this format: YYYY-MM-DD HH:MM:SS

    Example of getting the timestamp for a given date:
    $timestamp = strtotime("2014-10-09 11:10:00");

    And it will be 24 hour time, so 9PM is 21:00:00

    Once you have a valid timestamp, example 1412820797,
    you can manipulate it as an integer. The timestamp resolution
    is 'seconds', so 4 hours would be 1440 seconds.

    At this point, do all calculations as integers, using the timestamp integer.

    Example:
    if(strtotime($ticketTimestamp) <= strtotime($ticketTimestamp)-1440)

    All calculations by timestamp, and then whenever you need a human readable,
    convert it back. Example: echo date("m/d/Y h:i:s",$ticketTimestamp);
    Last edited by mlseim; Oct 08th, 2014 at 08:47 PM.


  4. #3
    Senior Member Noteleklabs's Avatar
    Join Date
    Jun 2012
    Location
    NC
    Posts
    217
    Member #
    31890
    Liked
    28 times
    Thanks! I'm not at my computer right now, so I can't check if these work, but it makes a whole lot of sense. (P.S, I am importing a ton of other scripts on this page, and do set the timezone)
    Hey you! Go make something!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com