> apropos: > anyone have a utility to calculate the > number of days between two given dates? > i mean - easily? no perl script > with dozens of modules, please!
I'd do this, assuming you have the GNU version of date:
#! /bin/sh
expr \( `date -d "$2" +%s` - `date -d "$1" +%s` \) / 86400
This assumes that you consider the difference between, say, 'jan 1' and 'jan
4' to be 3 days, but the difference between '12 pm jan 1 2002' and '12 am
jan 4 2002' to be 2 days.
Here's the perl script i use to make my X-Last-Reboot header. It does the
opposite -- it determines the date that was n seconds ago:
#! /usr/bin/perl -W
use strict;
open X, '/proc/uptime' or die;
defined (my $time = <X>) or die;
$time =~ s/ .*// or die;
my $days = int ($time / 86400);
my $hours = int (($time % 86400) / 3600);
my $mins = int (($time % 3600) / 60);
my $secs = int ($time % 60);
my (undef, undef, undef, $day, $mon, $year) = localtime (time - $time);
$year += 1900;
$mon = qw(January February March April May June July
August September October November December)[$mon];
print "$mon $day, $year ($days days ago)\n";
msg26359/pgp00000.pgp
Description: PGP signature
