954,180 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Days to year and month

Hi Guys How to convert number of days to number of year and month in Perl.

Prakash_8111
Newbie Poster
21 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

I like to use Date::Manip, but it is rather large.

http://search.cpan.org/~sbeck/Date-Manip-6.11/lib/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.

use Date::Manip;
$ENV{TZ}="EST";
use strict;
use warnings;
my $ptoday=ParseDate("today");
my $ftoday=UnixDate($ptoday,"%m/%d/%Y");
print "$ftoday\n";
my $month=UnixDate($ptoday,"%m");
my $day=UnixDate($ptoday,"%d");
my $year=UnixDate($ptoday,"%Y");

my $dayofyear=Date_DayOfYear($month,$day,$year);
print "$dayofyear\n";
mitchems
Posting Whiz in Training
295 posts since Feb 2009
Reputation Points: 26
Solved Threads: 38
 

Here's a little additional code for what you want...

use Date::Manip;
$ENV{TZ}="EST";
use strict;
use warnings;
my $ptoday=ParseDate("today");
my $ftoday=UnixDate($ptoday,"%m/%d/%Y");
print "$ftoday\n";
my $month=UnixDate($ptoday,"%m");
my $day=UnixDate($ptoday,"%d");
my $year=UnixDate($ptoday,"%Y");

my $dayofyear=Date_DayOfYear($month,$day,$year);
print "$dayofyear\n";

my $ndate=ParseDate("this $dayofyear day of this year");
my $fdate=UnixDate($ptoday,"%m/%d");
print "$fdate\n";
mitchems
Posting Whiz in Training
295 posts since Feb 2009
Reputation Points: 26
Solved Threads: 38
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You