*alexandre* has asked for the wisdom of the Perl Monks concerning the following question:
But the result is not correct anymore it's give the resultat for the difference between today and the 2013-07-03 00:00:00 as the following result 734581 J 6 H 34 M 26 Sec where J is number of days h hours M minutes and sec secondssub timeDiff { local our $invoke = shift || ''; local our $date1 = shift || ''; local our $date2 = shift || ''; #'2005-08-02 0:26:47', date2 => '2005-08-03 13:27:46' local our @offset_days = qw(0 31 59 90 120 151 181 212 243 273 30 +4 334); local our $year1 = substr($date1, 0, 4); local our $month1 = substr($date1, 5, 2); local our $day1 = substr($date1, 8, 2); local our $hh1 = substr($date1,11, 2) || 0; local our $mm1 = substr($date1,14, 2) || 0; local our $ss1 = substr($date1,17, 2) if (length($date1) > 16); #$ss1 ||= 0; local our $year2 = substr($date2, 0, 4); local our $month2 = substr($date2, 5, 2); local our $day2 = substr($date2, 8, 2); local our $hh2 = substr($date2,11, 2) || 0; local our $mm2 = substr($date2,14, 2) || 0; local our $ss2 = substr($date2,17, 2) if (length($date2) > 16); #$ss2 ||= 0; local our $total_days1 = $offset_days[$month1 - 1] + $day1 + 365 * + $year1; local our $total_days2 = $offset_days[$month2 - 1] + $day2 + 365 * + $year2; local our $days_diff = $total_days2 - $total_days1; local our $seconds1 = $total_days1 * 86400 + $hh1 * 3600 + $mm1 * +60 + $ss1; local our $seconds2 = $total_days2 * 86400 + $hh2 * 3600 + $mm2 * +60 + $ss2; local our $ssDiff = $seconds2 - $seconds1; local our $dd = int($ssDiff / 86400); local our $hh = int($ssDiff / 3600) - $dd * 24; local our $mm = int($ssDiff / 60) - $dd * 1440 - $hh * 6 +0; local our $ss = int($ssDiff / 1) - $dd * 86400 - $hh * 360 +0 - $mm * 60; return "$dd J $hh H $mm M $ss Sec"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DIfference in days hours and second between dates
by davido (Cardinal) on Jun 13, 2013 at 15:56 UTC | |
by space_monk (Chaplain) on Jun 13, 2013 at 16:08 UTC | |
by davido (Cardinal) on Jun 13, 2013 at 16:11 UTC | |
|
Re: DIfference in days hours and second between dates
by space_monk (Chaplain) on Jun 13, 2013 at 15:55 UTC | |
|
Re: DIfference in days hours and second between dates
by perlfan (Parson) on Jun 13, 2013 at 16:10 UTC | |
|
Re: DIfference in days hours and second between dates
by poj (Abbot) on Jun 13, 2013 at 16:08 UTC |