Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date manipulations

Status
Not open for further replies.

teroy

Programmer
Oct 17, 2000
67
AU
Hi there..
I have a variable which contains a date..say
my $var="1940/12/12/";

Is there any module around that gets the difference between this date and the current time.

So basically something which returns

($year,$month,$days)

So it can be presented like
You are 50 years, 3 months and 2 days old etc...

Thanks in advance :)
 
basicaly u need to convert the time to seconds and than compare to time variable. After that the localtime function will create an array that contains years, months, minutes etc. So the script would work somehow like:
(@first_time) = split(/\//,$time);
$first_in_seconds = ($first_time[0]-1970)*365*86400 + $first_time[1]*86400*30 +$first_time[2]*86400;
$delta =abs(time - $first_in_seconds);
(@delta_time) = localtime($delta);
u will have to play around a bit with converting your time to seconds because the actual time is measured from the 1.1. 1970...
robin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top