1
How do I get the value days of a DateInterval through the method date_interval_format()?
I tried it this way, but it didn’t work:
$var = date_interval_format($diferenca, '%days');

1
How do I get the value days of a DateInterval through the method date_interval_format()?
I tried it this way, but it didn’t work:
$var = date_interval_format($diferenca, '%days');

1
I did it that way and it worked:
$var = $diferenca->days;
$var received the 36 value I wanted !
0
Following the PHP manual you can use format('%a') to format a date difference, or days.
Both give what you seek.
format('%a')Total number of days as a result of a Datetime::diff()
namely the total number of days between the two dates.
Example:
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-23');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%a'); // dá 12
daysIt also says in the Manual of the Class Datetime who own a property days whose description is:
days
If the Dateinterval Object was created by Datetime::diff(), then this is the total number of days between the start and end Dates. Otherwise, days will be FALSE.
Translated would be:
If the range object is created with Datetime::diff() then it will be the total number of days between dates. Otherwise the value will be false.
Browser other questions tagged php dateinterval
You are not signed in. Login or sign up in order to post.
Have you tried using something like $difca->format('%d days'); ?
– Armando K.
Already yes. This way is returned "6 days", and not the 36 I need ! (6 days + 30 days of 1 month)
– Raphael Prado de Oliveira
What do you have in
$diferenca? seconds? wouldn’t that divide by 606024 and have days? with an optional rounding.– Sergio
The $difference is a variable of the type Dateinterval, as shown in the image above ! And I want to get the value 36 of days
– Raphael Prado de Oliveira
You can show where you get that
$diferenca?– Sergio
Thus Sergio : $difca = $dataFinal->diff($stardate); I make the difference between two Datetime.
– Raphael Prado de Oliveira