Days Since/Until
Posted May 2nd, 2005 @ 11:20am by Erik J. Barzeski
I added a "days since/until" countdown area beneath my picture on the main page only today. Relatively simple:
<? function figger($thingy) { $calc = intval(strtotime($thingy)) - todays_strtotime(); if($calc > 0) { echo days_until($thingy); } else echo days_since($thingy); }
function days_until($target) { $string = intval((strtotime($target) - todays_strtotime()) / (60 * 60 * 24)); $string .= " days until"; return "<strong>$string</strong>"; }
function days_since($target) { $string = intval((todays_strtotime() - strtotime($target)) / (60 * 60 * 24)); $string .= " days since"; return "<strong>$string</strong>"; }
function todays_strtotime() { return strtotime(date("Y-m-d")); } ?>
Then for each date, I simply have a code like this:
<?=figger('2004-10-12');?> moving back to PA.
Posted 02 May 2005 at 11:55am #
Hey, cool. Mind if I borrow that for my wedding blog?
Posted 02 May 2005 at 11:59am #
It's on my blog for all to use. Go ahead.
Posted 15 Jan 2007 at 3:00pm #
Updated with the most recent code. The previous one occasionally returned negative values.
Posted 03 Apr 2007 at 10:06pm #
Erik,
This is just the thing that I have been looking all over for. Unlike other "counters" that I have tryed, this is the best and cuts down the fluff and gets right to the point of how many days until or have gone by. Thanks and I hope that you don't mind that I use it on my site.