Subscribe to
NSLog(); Header Image

Days Since/Until

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);
        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.

4 Responses to "Days Since/Until"

  1. Hey, cool. Mind if I borrow that for my wedding blog?

  2. It's on my blog for all to use. Go ahead.

  3. Updated with the most recent code. The previous one occasionally returned negative values.

  4. 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.