phildeman has asked for the wisdom of the Perl Monks concerning the following question:
I currently use the method subtract_datetime to determine the remaining time available. In some cases the results returned are correct. In some cases the results returned are way off.
Below is how it is being used.
# the DateTime object, $endDate, normally comes from a database. But I created a DateTime object for this example. #<p>my $endDate = DateTime->new(year => 2015, month => 02, day => 24, t +ime_zone => 'America/New_York');
<p>my $dt1 = DateTime->now( 'time_zone' => 'America/New_York' ); my $duration_obj = $endDate->subtract_datetime($dt1) if $user_obj;</p> <p>print "Expires in: " . $duration_obj->months() . " months, " . $dur +ation_obj->weeks() . " weeks, " . $duration_obj->days() . " days";</p +>
As I indicated, sometimes the results are correct and sometimes it isn't. Is there something I am doing wrong? Or is there another method I can use with DateTime to return consistent results?
***EDITED***
So, if $endDate = "2015-02-24", the result I am getting is 5 months, 2 weeks, 0 days. Whereas, the result should be 0 months, 0 weeks, 5 days, based on today's date (2015-02-19).
However, if $endDate = "2015-06-16' the result is: 3 months, 3 weeks, 3 days. That is correct.
|
|---|