Errors when adding/subtracing dates using seconds - Brian Moon

Courtesy Planet PHP  Mon, 01/16/2012 - 15:55

This just came up today again for me. I have said it before, but even I get lazy and forget. When doing math with dates such as adding days it is really quick to think this works:
<?php

$date = "2011-11-01";

// add 15 days

$new_date = date("Y-m-d", strtotime($date) + (86400 * 15));

// $new_date should be 2011-11-16 right?

echo $new_date;

?>
This yields `2011-11-15`.

The problem with this is that it assume that there are only 86400 seconds in...


 

More related items

Why LTE sucks (your battery, that is)
LTE phones are fastest things on the airwaves, but they can also suck a battery dry in a few hours. Here are five reasons why your new Samsung Galaxy Nexus or HTC Vivid is going dead right...

/dev/hell Podcast Episode #5 - Brian Moon
I was privileged to be invited to be a part of the /dev/hell podcast this week. Thanks to Chris and Ed for having me on. Check it out. And subscribe to their podcast.

Brian Moon's Blog: Check for a TTY or interactive...
In a new post to his blog Brian Moon describes a need he had for detecting if the client or user calling a PHP script was using an interactive terminal (TTY) or not: Let's say I am trying...


 

Post new comment

The content of this field is kept private and will not be shown publicly.
computer-internet.marc8.com