fork download
  1. <?php
  2.  
  3. define( 'MINUTE_IN_SECONDS', 60 );
  4. define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS );
  5. define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );
  6. define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
  7. define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
  8.  
  9. function current_time($type, $gmt = 0){
  10. switch($type){
  11. case 'mysql':
  12. return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( null * HOUR_IN_SECONDS ) ) );
  13. case 'timestamp':
  14. return ( $gmt ) ? time() : time() + ( null * HOUR_IN_SECONDS );
  15. }
  16. }
  17.  
  18. $diff = strtotime('2014-10-10 14:49:33') - strtotime(current_time('mysql'));
  19. $hours = $diff / (60 * 60);
  20.  
  21. echo 'Expected: ';
  22. echo $hours;
  23.  
  24. echo PHP_EOL;
  25.  
  26. $diff = strtotime('2014-10-10 14:49:33') - strtotime(current_time('Y-m-d H:i:s'));
  27. $hours = $diff / (60 * 60);
  28.  
  29. echo 'Received: ';
  30. echo $hours;
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Expected: -6.9930555555556
Received: 392486.82583333