3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Query timestamp of entry //returns like this $entrydatetime = "2013-11-20 17:36:18"; //get current time $now = new \DateTime(); // Use DateTime on $entrydatetime $entrydatetime = new \DateTime($entrydatetime); // Seconds echo $now->getTimestamp() - $entrydatetime->getTimestamp() . "seconds\n"; // Human readable is more complex $age = $entrydatetime->diff($now); var_dump($age); // DateInterval if ($age->years > 0) { echo $age->format('%y years ago'); } else if ($age->months > 0) { echo $age->format('%m months ago'); } else if ($age->days > 0) { echo $age->format('%a days ago'); } else { echo $age->format('%h hours, %i minutes ago'); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSgFs
function name:  (null)
number of ops:  51
compiled vars:  !0 = $entrydatetime, !1 = $now, !2 = $age
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, '2013-11-20+17%3A36%3A18'
   10     1        NEW                                              $4      'DateTime'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   13     4        NEW                                              $7      'DateTime'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $7
   17     8        INIT_METHOD_CALL                                         !1, 'getTimestamp'
          9        DO_FCALL                                      0  $10     
         10        INIT_METHOD_CALL                                         !0, 'getTimestamp'
         11        DO_FCALL                                      0  $11     
         12        SUB                                              ~12     $10, $11
         13        CONCAT                                           ~13     ~12, 'seconds%0A'
         14        ECHO                                                     ~13
   21    15        INIT_METHOD_CALL                                         !0, 'diff'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $14     
         18        ASSIGN                                                   !2, $14
   22    19        INIT_FCALL                                               'var_dump'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                                 
   24    22        FETCH_OBJ_R                                      ~17     !2, 'years'
         23        IS_SMALLER                                               0, ~17
         24      > JMPZ                                                     ~18, ->30
   25    25    >   INIT_METHOD_CALL                                         !2, 'format'
         26        SEND_VAL_EX                                              '%25y+years+ago'
         27        DO_FCALL                                      0  $19     
         28        ECHO                                                     $19
         29      > JMP                                                      ->50
   26    30    >   FETCH_OBJ_R                                      ~20     !2, 'months'
         31        IS_SMALLER                                               0, ~20
         32      > JMPZ                                                     ~21, ->38
   27    33    >   INIT_METHOD_CALL                                         !2, 'format'
         34        SEND_VAL_EX                                              '%25m+months+ago'
         35        DO_FCALL                                      0  $22     
         36        ECHO                                                     $22
         37      > JMP                                                      ->50
   28    38    >   FETCH_OBJ_R                                      ~23     !2, 'days'
         39        IS_SMALLER                                               0, ~23
         40      > JMPZ                                                     ~24, ->46
   29    41    >   INIT_METHOD_CALL                                         !2, 'format'
         42        SEND_VAL_EX                                              '%25a+days+ago'
         43        DO_FCALL                                      0  $25     
         44        ECHO                                                     $25
         45      > JMP                                                      ->50
   31    46    >   INIT_METHOD_CALL                                         !2, 'format'
         47        SEND_VAL_EX                                              '%25h+hours%2C+%25i+minutes+ago'
         48        DO_FCALL                                      0  $26     
         49        ECHO                                                     $26
   32    50    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.04 ms | 1400 KiB | 15 Q