Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lurch3528yAlmost every time format ever will give you that. Dates aren't what you want them to be, they're the seconds since UNIX epoch, so if you subtract an int of seconds to get the 31st of a 30 day month, obviously, you'll just get the day after the 30th... it grabs the seconds, then converts it to a Date format. There are too many fringe cases to try to error out every time someone messes that up, most people prefer this format.
-
Meki1868yAtleast it's consistent... What are you trying to get? The last day of the previous month?
-
xNeko498yDoesn't matter what language you use, working with date and time with high precision is always hard. So always use a library that specialize on it. carbon.nesbot.com is a great one for php.
On the other hand, 1 month is generally 30 days so isn't quite logical that it returns 1/12/15? cmiiw -
fan120028yMake use of the Carbon package if you can. It gives you great power when it comes to dates.
-
if you are frustrated just create a new library to mend your frustration. This is how projects are born.
FUCK YOU PHP, WHY THE FUCK DO YOU GIVE ME DECEMBER 1ST WHEN I DO
strtotime('-1 month', '12/31/2015)
USING DateTime PRODUCES THE SAME FUCKING RESULT. ARE YOU FUCKING RETARDED OR WHAT?
YEAH I KNOW NOVEMBER DOESN'T HAVE 31ST BUT YOU COULD AT LEAST RETURN 30TH OR EVEN RAISE A WARNING, YOU FUCKING PIECE OF SHIT.
undefined