CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Get last week/month number

 



neuwerld
New User

Oct 16, 2013, 2:56 AM

Post #1 of 3 (549 views)
Get last week/month number Can't Post

Hey!

Im working on a project of my own, I need to be able to easy get the last week/month, this is because I need to do some calculations between this month and the last one. Haven't found an easy way of doing this.
I would like to have it like this:

Last week: 2013-41
Last month: 2013-09

All help is appreciated.

Best regards


neuwerld
New User

Oct 16, 2013, 3:22 AM

Post #2 of 3 (548 views)
Re: [neuwerld] Get last week/month number [In reply to] Can't Post

my $today = localtime;
my $date_week_ago = DateCalc('1 week ago', $today);
$date_week_ago = join '-', UnixDate($date_week_ago, '%Y', '%W');

my $date_month_ago = DateCalc('1 month ago', $today);
$date_month_ago = join '-', UnixDate($date_month_ago, '%Y', '%m');

This is how i solved it, kinda simple when finding DateCalc function.

Peace!


Laurent_R
Veteran / Moderator

Oct 16, 2013, 2:03 PM

Post #3 of 3 (537 views)
Re: [neuwerld] Get last week/month number [In reply to] Can't Post

Maybe you should specify that this function is available by loading specific CPAN modules such as Date::Calc and/or possibly others. There is a wealth of such modules to do all kind of data and time calculations, the difficulty is not to find one, but more to find the most appropriate one for your needs.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives