I can find many examples to help compare and difference times, but only when the time is stored in a timestamp. My time is stored in the format hh:mm:ss (e.g. 12:30:02). I need to be able to check if  30 seconds have elapsed. For example if the start time was 12:30:02, and the time is now 12:30:33 then yes its over 30 seconds have elapsed and if the time is now 12:30:31 the 30 seconds have not elapsed.
            Asked
            
        
        
            Active
            
        
            Viewed 98 times
        
    -1
            
            
         
    
    
        Ryan Amos
        
- 5,422
- 4
- 36
- 56
 
    
    
        Matt Leyland
        
- 2,149
- 3
- 15
- 16
- 
                    2What's your question? What have you tried? – j08691 Jan 15 '15 at 21:31
- 
                    Do you mean checking time with php or sql ? – Whirlwind Jan 15 '15 at 21:32
- 
                    1What happens at 23:59:59? – ceejayoz Jan 15 '15 at 21:32
- 
                    $lastcheck = $row["juniper_last_time"]; $date = strtotime($lastcheck); if($date > time() + 7990) { echo 'yes'; if (0 == $status) { echo "YES"; } else { echo "NO"; } – Matt Leyland Jan 15 '15 at 21:32
- 
                    2Maybe this will help: http://stackoverflow.com/questions/2915864/php-how-to-find-the-time-elapsed-since-a-date-time – MarkP Jan 15 '15 at 21:32
1 Answers
4
            If you can supply the entire datetime like 2015-01-01 12:30:02, then strtotime() is your hero:
<?php
$input = '2015-01-01 12:30:02';
if (time() - strtotime($input) > 30)
    echo 'Too old.';
time() gives you the current time in seconds since the "Unix epoch," and strtotime() converts a datetime string into seconds since the epoch.
 
    
    
        mopo922
        
- 6,293
- 3
- 28
- 31