3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dateDiff($startdate, $enddate) { $first = $startdate < $enddate ? $startdate : $enddate; $second = $startdate < $enddate ? $enddate : $startdate; $inbetween = $second - $first; $firsttemp = $first; $months = 0; $days = 0; while(TRUE) { if($firsttemp + 86400 * date('t', $firsttemp) <= $second) { $months += 1; $firsttemp += 86400 * date('t', $firsttemp); } else { if($second - $firsttemp >= 86400) { $days = floor(($second - $firsttemp) / 86400); } break; } } $years = floor($months / 12); $months = $months % 12; $hours = floor($inbetween / 60 / 60 % 24); $minutes = floor($inbetween / 60 % 60); $seconds = $inbetween % 60; $dateObj = new stdClass(); $dateObj->y = $years; $dateObj->m = $months; $dateObj->d = $days; $dateObj->h = $hours; $dateObj->i = $minutes; $dateObj->s = $seconds; $dateObj->days = floor($inbetween / 86400); return $dateObj; } $str1 = "1970-01-01"; $str2 = "2009-01-01"; $tempdate1 = $str1; $n = 0; while(strtotime($tempdate1) <= strtotime($str2)) { $mydate = dateDiff(strtotime($str1), strtotime($tempdate1)); $string2 = "(" . $mydate->days . ") difference " . $mydate->y . " years, " . $mydate->m . " months, " . $mydate->d . " days, " . $mydate->h . " hours, " . $mydate->i . " minutes, and " . $mydate->s . " seconds"; echo "<span style=\"color:green;\">", $string1, " - ", $string2, "</span><br />"; $n += 321; $tempdate1 = $str1 . " +" . $n . " sec"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 5
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 5
Branch analysis from position: 56
Branch analysis from position: 5
filename:       /in/FZr19
function name:  (null)
number of ops:  57
compiled vars:  !0 = $str1, !1 = $str2, !2 = $tempdate1, !3 = $n, !4 = $mydate, !5 = $string2, !6 = $string1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, '1970-01-01'
   46     1        ASSIGN                                                   !1, '2009-01-01'
   48     2        ASSIGN                                                   !2, !0
   49     3        ASSIGN                                                   !3, 0
   51     4      > JMP                                                      ->48
   52     5    >   INIT_FCALL                                               'datediff'
          6        INIT_FCALL                                               'strtotime'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $11     
          9        SEND_VAR                                                 $11
         10        INIT_FCALL                                               'strtotime'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $12     
         13        SEND_VAR                                                 $12
         14        DO_FCALL                                      0  $13     
         15        ASSIGN                                                   !4, $13
   53    16        FETCH_OBJ_R                                      ~15     !4, 'days'
         17        CONCAT                                           ~16     '%28', ~15
         18        CONCAT                                           ~17     ~16, '%29+difference+'
         19        FETCH_OBJ_R                                      ~18     !4, 'y'
         20        CONCAT                                           ~19     ~17, ~18
         21        CONCAT                                           ~20     ~19, '+years%2C+'
         22        FETCH_OBJ_R                                      ~21     !4, 'm'
         23        CONCAT                                           ~22     ~20, ~21
         24        CONCAT                                           ~23     ~22, '+months%2C+'
         25        FETCH_OBJ_R                                      ~24     !4, 'd'
         26        CONCAT                                           ~25     ~23, ~24
         27        CONCAT                                           ~26     ~25, '+days%2C+'
         28        FETCH_OBJ_R                                      ~27     !4, 'h'
         29        CONCAT                                           ~28     ~26, ~27
         30        CONCAT                                           ~29     ~28, '+hours%2C+'
         31        FETCH_OBJ_R                                      ~30     !4, 'i'
         32        CONCAT                                           ~31     ~29, ~30
         33        CONCAT                                           ~32     ~31, '+minutes%2C+and+'
         34        FETCH_OBJ_R                                      ~33     !4, 's'
         35        CONCAT                                           ~34     ~32, ~33
         36        CONCAT                                           ~35     ~34, '+seconds'
         37        ASSIGN                                                   !5, ~35
   55    38        ECHO                                                     '%3Cspan+style%3D%22color%3Agreen%3B%22%3E'
         39        ECHO                                                     !6
         40        ECHO                                                     '+-+'
         41        ECHO                                                     !5
         42        ECHO                                                     '%3C%2Fspan%3E%3Cbr+%2F%3E'
   57    43        ASSIGN_OP                                     1          !3, 321
   58    44        CONCAT                                           ~38     !0, '+%2B'
         45        CONCAT                                           ~39     ~38, !3
         46        CONCAT                                           ~40     ~39, '+sec'
         47        ASSIGN                                                   !2, ~40
   51    48    >   INIT_FCALL                                               'strtotime'
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                         $42     
         51        INIT_FCALL                                               'strtotime'
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $43     
         54        IS_SMALLER_OR_EQUAL                                      $42, $43
         55      > JMPNZ                                                    ~44, ->5
   59    56    > > RETURN                                                   1

Function datediff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 20
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 45
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
Branch analysis from position: 12
filename:       /in/FZr19
function name:  dateDiff
number of ops:  92
compiled vars:  !0 = $startdate, !1 = $enddate, !2 = $first, !3 = $second, !4 = $inbetween, !5 = $firsttemp, !6 = $months, !7 = $days, !8 = $years, !9 = $hours, !10 = $minutes, !11 = $seconds, !12 = $dateObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        IS_SMALLER                                               !0, !1
          3      > JMPZ                                                     ~13, ->6
          4    >   QM_ASSIGN                                        ~14     !0
          5      > JMP                                                      ->7
          6    >   QM_ASSIGN                                        ~14     !1
          7    >   ASSIGN                                                   !2, ~14
    5     8        IS_SMALLER                                               !0, !1
          9      > JMPZ                                                     ~16, ->12
         10    >   QM_ASSIGN                                        ~17     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~17     !0
         13    >   ASSIGN                                                   !3, ~17
    6    14        SUB                                              ~19     !3, !2
         15        ASSIGN                                                   !4, ~19
    7    16        ASSIGN                                                   !5, !2
    9    17        ASSIGN                                                   !6, 0
   10    18        ASSIGN                                                   !7, 0
   12    19      > JMP                                                      ->46
   13    20    >   INIT_FCALL                                               'date'
         21        SEND_VAL                                                 't'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $24     
         24        MUL                                              ~25     $24, 86400
         25        ADD                                              ~26     !5, ~25
         26        IS_SMALLER_OR_EQUAL                                      ~26, !3
         27      > JMPZ                                                     ~27, ->36
   14    28    >   ASSIGN_OP                                     1          !6, 1
   15    29        INIT_FCALL                                               'date'
         30        SEND_VAL                                                 't'
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $29     
         33        MUL                                              ~30     $29, 86400
         34        ASSIGN_OP                                     1          !5, ~30
         35      > JMP                                                      ->46
   17    36    >   SUB                                              ~32     !3, !5
         37        IS_SMALLER_OR_EQUAL                                      86400, ~32
         38      > JMPZ                                                     ~33, ->45
   18    39    >   INIT_FCALL                                               'floor'
         40        SUB                                              ~34     !3, !5
         41        DIV                                              ~35     ~34, 86400
         42        SEND_VAL                                                 ~35
         43        DO_ICALL                                         $36     
         44        ASSIGN                                                   !7, $36
   21    45    > > JMP                                                      ->47
   12    46    > > JMPNZ                                                    <true>, ->20
   25    47    >   INIT_FCALL                                               'floor'
         48        DIV                                              ~38     !6, 12
         49        SEND_VAL                                                 ~38
         50        DO_ICALL                                         $39     
         51        ASSIGN                                                   !8, $39
   26    52        MOD                                              ~41     !6, 12
         53        ASSIGN                                                   !6, ~41
   28    54        INIT_FCALL                                               'floor'
         55        DIV                                              ~43     !4, 60
         56        DIV                                              ~44     ~43, 60
         57        MOD                                              ~45     ~44, 24
         58        SEND_VAL                                                 ~45
         59        DO_ICALL                                         $46     
         60        ASSIGN                                                   !9, $46
   29    61        INIT_FCALL                                               'floor'
         62        DIV                                              ~48     !4, 60
         63        MOD                                              ~49     ~48, 60
         64        SEND_VAL                                                 ~49
         65        DO_ICALL                                         $50     
         66        ASSIGN                                                   !10, $50
   30    67        MOD                                              ~52     !4, 60
         68        ASSIGN                                                   !11, ~52
   32    69        NEW                                              $54     'stdClass'
         70        DO_FCALL                                      0          
         71        ASSIGN                                                   !12, $54
   34    72        ASSIGN_OBJ                                               !12, 'y'
         73        OP_DATA                                                  !8
   35    74        ASSIGN_OBJ                                               !12, 'm'
         75        OP_DATA                                                  !6
   36    76        ASSIGN_OBJ                                               !12, 'd'
         77        OP_DATA                                                  !7
   37    78        ASSIGN_OBJ                                               !12, 'h'
         79        OP_DATA                                                  !9
   38    80        ASSIGN_OBJ                                               !12, 'i'
         81        OP_DATA                                                  !10
   39    82        ASSIGN_OBJ                                               !12, 's'
         83        OP_DATA                                                  !11
   40    84        INIT_FCALL                                               'floor'
         85        DIV                                              ~64     !4, 86400
         86        SEND_VAL                                                 ~64
         87        DO_ICALL                                         $65     
         88        ASSIGN_OBJ                                               !12, 'days'
         89        OP_DATA                                                  $65
   42    90      > RETURN                                                   !12
   43    91*     > RETURN                                                   null

End of function datediff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.89 ms | 1415 KiB | 20 Q