3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dateTimeDiff($start, $end, $units = 'Days') { $start_ts = strtotime($start); $end_ts = strtotime($end); $diff = $end_ts - $start_ts; $divider = 86400; if ($units != 'Days') { $divider = $divider / 24; if ($units != 'Hours') { $divider = $divider / 60; if ($units != 'Minutes') { $divider = $divider / 60; } } } return round($diff / $divider); } $datetime1 = date_create('now'); $datetime2 = date_create('13-11-2013'); $interval = date_diff($datetime1, $datetime2); echo dateTimeDiff(date('Y-m-d'), date_create('13-11-2013')); echo "\n"; echo $interval->format('%R%a dias'); echo "\n".'24-05-2013 (-143 dias)';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l4Lgm
function name:  (null)
number of ops:  31
compiled vars:  !0 = $datetime1, !1 = $datetime2, !2 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'date_create'
          1        SEND_VAL                                                 'now'
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !0, $3
   24     4        INIT_FCALL                                               'date_create'
          5        SEND_VAL                                                 '13-11-2013'
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
   25     8        INIT_FCALL                                               'date_diff'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   27    13        INIT_FCALL                                               'datetimediff'
         14        INIT_FCALL                                               'date'
         15        SEND_VAL                                                 'Y-m-d'
         16        DO_ICALL                                         $9      
         17        SEND_VAR                                                 $9
         18        INIT_FCALL                                               'date_create'
         19        SEND_VAL                                                 '13-11-2013'
         20        DO_ICALL                                         $10     
         21        SEND_VAR                                                 $10
         22        DO_FCALL                                      0  $11     
         23        ECHO                                                     $11
   28    24        ECHO                                                     '%0A'
   29    25        INIT_METHOD_CALL                                         !2, 'format'
         26        SEND_VAL_EX                                              '%25R%25a+dias'
         27        DO_FCALL                                      0  $12     
         28        ECHO                                                     $12
   31    29        ECHO                                                     '%0A24-05-2013+%28-143+dias%29'
         30      > RETURN                                                   1

Function datetimediff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 26
Branch analysis from position: 26
filename:       /in/l4Lgm
function name:  dateTimeDiff
number of ops:  32
compiled vars:  !0 = $start, !1 = $end, !2 = $units, !3 = $start_ts, !4 = $end_ts, !5 = $diff, !6 = $divider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'Days'
    4     3        INIT_FCALL                                               'strtotime'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !3, $7
    5     7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !4, $9
    6    11        SUB                                              ~11     !4, !3
         12        ASSIGN                                                   !5, ~11
    8    13        ASSIGN                                                   !6, 86400
    9    14        IS_NOT_EQUAL                                             !2, 'Days'
         15      > JMPZ                                                     ~14, ->26
   10    16    >   DIV                                              ~15     !6, 24
         17        ASSIGN                                                   !6, ~15
   11    18        IS_NOT_EQUAL                                             !2, 'Hours'
         19      > JMPZ                                                     ~17, ->26
   12    20    >   DIV                                              ~18     !6, 60
         21        ASSIGN                                                   !6, ~18
   13    22        IS_NOT_EQUAL                                             !2, 'Minutes'
         23      > JMPZ                                                     ~20, ->26
   14    24    >   DIV                                              ~21     !6, 60
         25        ASSIGN                                                   !6, ~21
   19    26    >   INIT_FCALL                                               'round'
         27        DIV                                              ~23     !5, !6
         28        SEND_VAL                                                 ~23
         29        DO_ICALL                                         $24     
         30      > RETURN                                                   $24
   20    31*     > RETURN                                                   null

End of function datetimediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.91 ms | 1403 KiB | 24 Q