Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Standards and Best Practices Databases and International Concerns DateTime Comparisons

marcelo pereira
marcelo pereira
3,201 Points

does not make sense

What would the output be from the following code? $mike = new DateTime('August 4th 1986'); $sally = new DateTime('July 1st 1988'); var_dump($sally < $mike);

1 Answer

Ron McCranie
Ron McCranie
7,837 Points

The answer is FALSE because $sally < $mike is the same as saying July 1st 1988 is less than August 4th 1986 which is not true.

marcelo pereira
marcelo pereira
3,201 Points

since both are DateTime code, is it the same as saying who was born on August 4th 1986 is older than who was born on July 1st 1988' ? So making it true in a date sense ?

Ron McCranie
Ron McCranie
7,837 Points

It would be true if it were comparing the 'ages' of people born on those days, but it's comparing the exact date of those two days.

Niclas Valentiner
Niclas Valentiner
8,947 Points

The best way to explain why it's not comparing the ages but the 'days' is that it works like comparing 2 integers.

I don't know if you know unix timestamps but it works pretty much the same: it's a number counting upwards the 'further in time' it is. Like 1988 is higher than 1986 because it's further from 0.