Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Date Manip Delta_Format

by epoch1 (Acolyte)
on Nov 09, 2016 at 13:47 UTC ( [id://1175598]=perlquestion: print w/replies, xml ) Need Help??

epoch1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, We've been using the following code on a legacy system for years but users have reported recently that something isn't working correctly:
$expected_date = '2016-11-05 14:00'; $actual_date = '2016-11-09 14:00'; my $delta = DateCalc($expected_date,$actual_date); #print $delta = 0:0:0:0:96:0:0 $delta = Delta_Format($delta,0,"%dh"); #print $delta = 0
I believe the final $delta value should be 4 (days) but it is 0. Does anyone know why this is happening and how I can rectify this? Thanks monks.

Replies are listed 'Best First'.
Re: Date Manip Delta_Format
by SBECK (Chaplain) on Nov 09, 2016 at 14:40 UTC
    From the Date::Manip documentation:
       %Xh  : print the value of field X and all
              larger units in terms of X
    
    so you are asking for the values of the fields of d (day) and higher in terms of days.

    The values of all fields higher are 0:0:0:0, which is a total of 0 days, so what you got is expected.

    It appears to me that what you are really asking for is the value of the delta in days, but ignoring the fact that a day is not strictly 24 hours (due to daylight saving time).

    The following will do that:

    Delta_Format($delta,'semi',0,'%dt') => 4
      By the way, the format of the delta did change (from an older 0:0:0:4:0:0:0 to a newer 0:0:0:0:96:0:0) to handle the fact that a day was not a constant length period of time. That change was quite a while ago though, so I wonder if you upgraded Date::Manip recently after a long period of using an older version. That would explain why this just started failing for you.
        Thank you. It was due to the module update.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1175598]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found