In perl there are three basic time routines, time, timelocal(), and 
localtime(). time returns current date/time in seconds since 1/1/70.
localtime() returns $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst
of the date/time when used. Its reverse is timelocal(),((use Time::Local;) to 
get at this subroutine) which returns the reverse, because you have to get 
the secondes of a date earlier than *now* before you can work with it.
All the strings returned are numeric, so for ex. $hour is 0,1,2...23 but 
globalized by 
@hour = (midnight,one,two,three...twelve,one,two,three..eleven) or
@hour = ("12","1","2"..."12","1","2"..."11") to get rid of the ugly 0 hour.
and returned by something like
$now=time;
($hour_text) = (localtime($now))[2];

I cut this out of a contest script I run, should give you an idea of how perl 
uses time() and localtime(). One thing to remember, timelocal() wont do a 
date earlier than 1970.

##
## Called with &get_date for date now 
## Called with &get_date($mtime) where mtime is a previous date in seconds
##
sub get_date
{
@day = (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
@month = ("01","02","03","04","05","06","07","08","09","10","11","12");
$p = "/";
$pp = "20";

        $mtime = time unless ($mtime);
        ($mday,$mon,$yr) = (localtime($mtime))[3,4,5];

$date = "$month[$mon]$p$mday$p$pp$yr";

}

On Saturday 22 September 2001 07:43, Joel Hammer wrote:
> Is there a builtin function to use with bash scripts to manipulate dates,
> for example, to subtract two dates or two times and get the difference
> between them?
> Thanks,
> Joel
>
> _______________________________________________
> http://linux.nf -- [EMAIL PROTECTED]
> Archives, Subscribe, Unsubscribe, Digest, Etc
> ->http://linux.nf/mailman/listinfo/linux-users

-- 
Ronnie
==================
Life can be a dream; or it can be a nightmare
it's all in your mind
_______________________________________________
http://linux.nf -- [EMAIL PROTECTED]
Archives, Subscribe, Unsubscribe, Digest, Etc 
->http://linux.nf/mailman/listinfo/linux-users

Reply via email to