On Fri, Nov 27, 2009 at 11:25 AM, Dermot <paik...@googlemail.com> wrote:
> 2009/11/27 Rob Coops <rco...@gmail.com>: > > On Fri, Nov 27, 2009 at 5:43 AM, raphael() <raphael.j...@gmail.com> > wrote: > >> > >> HOW CAN I COUNT ELAPSED DAYS ? > >> > >> I tried in localtime() days value like > >> > >> my @array_date = localtime(); > >> my $current_dayofyear = @array_date[7]; > >> > >> > >> But this would break on New year as "$current_dayofyear" would be reset. > >> > >> > >> SO HOW CAN I COUNT ELAPSED DAYS IF THE DATE FORMAT IS 01.01.2009? > >> > > > > > > Hi, > > > > This is a very old problem pretty much every single programmer has bumped > > into this one... So looking on CPAN <http://search.cpan.org> should be > able > > to provide you literally tens of modules used for date calculations in > all > > sorts and forms. I would advise having a look at Date::Manip which I > found > > very helpful for these kinds of problems. But if you are stubborn and > like > > to reinvent the wheel that is no problem of course but might be a little > > more difficult... > > I don't want to be controversial but I attended a Perl course this > week where the tutor came down firmly in the DataTime camp. It has > it's own site (http://datetime.perl.org/) as well as providing all the > features of Date::Calc (my favourite) and Date::Manip in a unified > manor. > > In the case above you would create a Duration object > (http://search.cpan.org/~drolsky/DateTime-0.51/lib/DateTime/Duration.pm) > and apply that to you existing DataTime object. > > HTH, > Dp. > DateTime will do just as well indeed, personally I like Date::Manip because it is the module I know best and so far it has done exactly what I wanted it to do without causing me any headaches. But as I said the choice on CPAN is quite big so pick what works best in your situation.