943,175 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 246
  • Perl RSS
Sep 1st, 2010
-1

Days to year and month

Expand Post »
Hi Guys How to convert number of days to number of year and month in Perl.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Prakash_8111 is offline Offline
21 posts
since Jun 2009
Sep 1st, 2010
0
Re: Days to year and month
I like to use Date::Manip, but it is rather large.

http://search.cpan.org/~sbeck/Date-M...Date/Manip.pod

You can do a TON of stuff with this module. Run the pod to text to get the full help text with formats, date calculations, etc.

Perl Syntax (Toggle Plain Text)
  1. use Date::Manip;
  2. $ENV{TZ}="EST";
  3. use strict;
  4. use warnings;
  5. my $ptoday=ParseDate("today");
  6. my $ftoday=UnixDate($ptoday,"%m/%d/%Y");
  7. print "$ftoday\n";
  8. my $month=UnixDate($ptoday,"%m");
  9. my $day=UnixDate($ptoday,"%d");
  10. my $year=UnixDate($ptoday,"%Y");
  11.  
  12. my $dayofyear=Date_DayOfYear($month,$day,$year);
  13. print "$dayofyear\n";
Reputation Points: 26
Solved Threads: 38
Posting Whiz in Training
mitchems is offline Offline
293 posts
since Feb 2009
Sep 1st, 2010
0
Re: Days to year and month
Here's a little additional code for what you want...

Perl Syntax (Toggle Plain Text)
  1. use Date::Manip;
  2. $ENV{TZ}="EST";
  3. use strict;
  4. use warnings;
  5. my $ptoday=ParseDate("today");
  6. my $ftoday=UnixDate($ptoday,"%m/%d/%Y");
  7. print "$ftoday\n";
  8. my $month=UnixDate($ptoday,"%m");
  9. my $day=UnixDate($ptoday,"%d");
  10. my $year=UnixDate($ptoday,"%Y");
  11.  
  12. my $dayofyear=Date_DayOfYear($month,$day,$year);
  13. print "$dayofyear\n";
  14.  
  15. my $ndate=ParseDate("this $dayofyear day of this year");
  16. my $fdate=UnixDate($ptoday,"%m/%d");
  17. print "$fdate\n";
Reputation Points: 26
Solved Threads: 38
Posting Whiz in Training
mitchems is offline Offline
293 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Configuration Syncronization
Next Thread in Perl Forum Timeline: verilog files comparision





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC