-1

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.

Ryan Amos
  • 5,422
  • 4
  • 36
  • 56
Matt Leyland
  • 2,149
  • 3
  • 15
  • 16

1 Answers1

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