Help Me Morbidly Count Down the Remaining Days of My Life!
September 27, 2007 3:16 PM   Subscribe

I would basically like to rip off, wholesale, some command-line script which will provide me a countdown -- only in days. No years, months, minutes, or seconds. Unfortunately, adapting an existing script is beyond my ken.

This idea of Kevin Kelly's inspired me to perhaps try something similar to motivate me towards working more diligently towards long-term personal goals, but I'm not an iGoogle user. I'd like to instead set it up as the result of a shell script which I can then pipe through GeekTool onto my Mac OS X desktop.

The only problem is that there is a lot of Googlenoise out there clogging up the results, and I can't seem to find the kind of script I'm looking for. I did find a countdown script that would tell it to me in years, months, days, horus minutes, and seconds -- but I really would prefer a days-only readout, similar to that depicted on the page. And I see various Javascript to include on webpages -- but I'm looking for something to be done locally, and I can't use the Javascript and then pipe it through lynx or links, since when I bring up such a page using either, the Javascript result doesn't seem to show. (I doubt lynx or links has Javascript support, do they?)

Anyway, can anyone point me towards a shell script that will take the present date, subtract it from a future date, and tell me the number of days between then and now?

I should add that I'm an idiot savante when it comes to shell scripting and Perl ... more of a splicer than anything resembling a programmer. I can sometimes look at code and grok a little of what it's saying, but telling me to embed the Doohickie:Flippa library into the Perl output by piping it through the black hole matrix into my Bananaphone is going to make me look at you blankly.

posted by WCityMike to Computers & Internet (5 answers total) 1 user marked this as a favorite
echo $((($(date +%s -d "2008-01-01") - $(date +%s -d now ))/86400))

Shoudl work in any bourne-like shell.
posted by fvw at 3:20 PM on September 27, 2007

But requires the GNU coreutils date(1) as the macOS version doesn't do -d. Oops.
posted by fvw at 3:23 PM on September 27, 2007

1. sudo cpan Date::Calc
That'll install the perl Date::Calc module and all its dependencies. You may have to go through a bit of questioning if you've never installed a module before -- accept all the defaults and you'll be fine. Defaults are displayed in square brackets and you can accept them just by pressing enter. If you've messed with script stuff even a little you should have the technical know-how to at least plow through it. It leads you through fairly well.

Anyway, that'll run for a minute or so. It might seem like a big deal, for all the stuff it'll print to your terminal window, but it really isn't, it's just some handy date code.

2. This perl script:
use strict;
use Date::Calc qw(Delta_Days Today);

my @target = (2008, 01, 01); # year, month, day

my $days = Delta_Days(Today(), @target);

print "$days days remaining.\n";

There's a lot of other things you can do with Date::Calc, if you're interested: documentation is here.
posted by blacklite at 4:28 PM on September 27, 2007

Depending on how dedicated you are to using pure shell script, either of these should do the trick (tested on 10.4):

I like the readability of this one:

python -c 'from datetime import *; print (date(2007, 10, 01) -'

This one allows a lot of flexibility specifying the date ("tomorrow", "next Tuesday", "January 1st 2008"):

echo '<?=(int)((strtotime("Oct 1")-time())/86400)?>' | php

Yeah, it's overkill, but it works.
posted by pocams at 4:29 PM on September 27, 2007

Now that I test again, my two pieces of code give different output. The first is "how many human days between now and then, inclusive", so there are four days from now to Oct 1st. The second is "how many full day-long intervals", so it returns three.
posted by pocams at 4:33 PM on September 27, 2007

« Older Is it too late to rescue my newly-installed djembe...   |   Art/Culture Festivals/Areas in Northern Vietnam? Newer »
This thread is closed to new comments.