htmanning has asked for the wisdom of the Perl Monks concerning the following question:
I've tried to spilt the numbers up and do some math, but it doesn't work. I'm ending up with negative numbers if the months are the same, etc., etc. This was my lame attempt. Can someone give me a better way?$hiredate = "2014-05-05"; $nowdate = "2016-04-15";
@words = split (/-/, $hiredate); $hire_yr = "@words[0]"; $hire_mo = "@words[1]"; $hire_day = "@words[2]"; @words_now = split (/-/, $ymd); $now_yr = "@words_now[0]"; $now_mo = "@words_now[1]"; $now_day = "@words_now[2]"; $since_yr = $now_yr - $hire_yr; $since_mo = $now_mo - $hire_mo; $since_day = $now_day - $hire_day; unless ($since_mo == abs($since_mo)) { $since_yr = $since_yr -1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I tell the time between two dates?
by Your Mother (Archbishop) on Apr 16, 2016 at 04:46 UTC | |
|
Re: How do I tell the time between two dates?
by kevbot (Vicar) on Apr 16, 2016 at 05:04 UTC | |
by htmanning (Friar) on Apr 16, 2016 at 05:26 UTC | |
by Your Mother (Archbishop) on Apr 16, 2016 at 05:56 UTC | |
by kevbot (Vicar) on Apr 16, 2016 at 06:04 UTC | |
|
Re: How do I tell the time between two dates?
by Marshall (Canon) on Apr 16, 2016 at 04:53 UTC | |
|
Re: How do I tell the time between two dates?
by hippo (Archbishop) on Apr 16, 2016 at 07:52 UTC | |
|
Re: How do I tell the time between two dates?
by Anonymous Monk on Apr 16, 2016 at 06:37 UTC |