How to include dateInterval property inside a variable

1

After you get the time difference between two input time fields (see this question ), I do not know how I can put these values inside variables, so I can use them in other functions.

The var_dump of variable $intervalo (which stores dateInterval ) is:

  

object (DateInterval) # 3 (15) {["y"] = > int (0) ["m"] = > int (0) ["d"] = > int (0) ["h"] = > int (5) ["i"] = > int (18) ["s"] = > int (0) ["weekday"] = > int (0) ["weekday_behavior"] = > int (0) ["first_last_day_of"] = > int (0) ["invert"] = > int (0) ["days"] = > int (0) ["special_type"] = > int (0) ["special_amount"] = > int (0) ["have_weekday_relative"] = > int (0) ["have_special_relative"] = > int (0)}

(in bold above are the fields that interest you)

Then I tried something like:

$hora = $intervalo[h]; 

or

$hora = $intervalo["h"];

or

$hora = $intervalo['h'];

But I think [h] is not a vector ... The question is: how to put property [h] in a variable?

I searched the man page, but my English is not there, so it did not work.

    
asked by anonymous 17.04.2015 / 04:09

1 answer

2

The first word of var_dump shows object so to access its properties, use the operator -> .

You can get the value as follows:

$hora = $intervalo->h;

or:

$hora = $intervalo->format('diferença de horas: %h');

List of valid parameters for format

    
17.04.2015 / 04:55