Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the days and "d" property in DateInterval

Tags:

php

datetime

When I use the DateInterval class it returns a property names "d" and then another property names "Days" I am really confused on what is the difference between the two. Can someone please explain.

Below is an example of the object that was returned in my code.

DateInterval(
y =
0
m =
1
d =
1
h =
3
i =
16
s =
6
weekday =
0
weekday_behavior =
0
first_last_day_of =
0
invert =
1
days =
31
special_type =
0
special_amount =
0
have_weekday_relative =
0
have_special_relative =
0
like image 595
json2021 Avatar asked May 25 '15 22:05

json2021


1 Answers

  • d - the days from the start of the month that need to be added after the months are added - (Feb 23 - Jan 1).d == 22)
  • days - the total number of days - (Feb 23 - Jan 1).days == 31 + 22)

From the documentation:

d

Number of days.

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.

Before PHP 5.4.20/5.5.4 instead of FALSE you will receive -99999 upon accessing the property.

like image 85
Eric Avatar answered Nov 12 '22 20:11

Eric