datetime - How can I calculate the number of days between two dates in Perl? -


Heilo,

I want to calculate (days using the default Perl installation only) The number of two dates is the format of both the dates as 04-May-09. (DD-MMM-YY)

I could not find the tutorial, whose date format was discussed. Should I build a Custom Deander Checker for this format? Reading on CPANn does not seem possible that this format is supported.

Thank you.

If you take care of accuracy, keep in mind that there are 86400 seconds not all days in this assumption Based on this, any solution will not be right for some cases.

This is a snippet that I keep around to calculate and display a few different ways to use the library. The last answer is printed, which you want, I think.

  #! / Usr / bin / perl -w use strict; Use date time; Use Date :: Format :: Duration; # XXX: Make your two dates here My $ d1 = Date Time- & gt; new (...); My $ d2 = DateTime- & gt; new (...); My $ dur = ($ d1> $ d2? ($ D1- & gt; subtraction_data_basolute ($ d2)): ($ d2- & gt; subtract_datetime_absolute ($ d1)); My $ f = Date Time :: Format :: Duration-> New (Pattern = & gt; '% Y Year,% M Month,% E Day,% H Hour,% M Minute,% S Second'); Print $ f- & gt; Format_digit ($ dur), "\ n"; $ Fear = $ d1- & gt; Delta_md ($ d2); My $ dy = int ($ dur-> delta_months / 12); My $ dm = $ dur- & gt; Delta_Memths% 12; Print "$ dy year $ dm month", $ dur- & gt; Delta_de, "day \ n"; Print $ der-> delta_mm, "months", $ der-> delta_de, "day \ n"; Print $ d1- & gt; Delta_de ($ d2) - & gt; Delta_day, "Day \ n";  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -