Given a month perl should split into weeks -



Given a month perl should split into weeks -

i trying split month 4 weeks using perl.say eg. input giving start date , end date. start date-09/01/2014 end date-09/30/2014

perl should split date range 4 different weeks.do have thought how proceed that.

thanks in advance..

4 weeks lasts 28 days. you've prefaced problem 30 day period.

assuming want week stand sunday - saturday, next code using time::piece of assistance you:

use strict; utilize warnings; utilize time::piece; utilize time::seconds; $start = '09/01/2014'; $end = '09/30/2014'; $fmt = '%m/%d/%y'; # normalized noon avoid dst $week_start = time::piece->strptime( $start, $fmt ) + 12 * one_hour; $month_end = time::piece->strptime( $end, $fmt ); while (1) { print $week_start->strftime($fmt), ' - '; $week_end = $week_start + one_day * ( 6 - $week_start->day_of_week ); if ( $week_end > $month_end ) { print $end, "\n"; last; } # print end of week , begin cycle next week print $week_end->strftime($fmt), "\n"; $week_start = $week_end + one_day; }

outputs:

09/01/2014 - 09/06/2014 09/07/2014 - 09/13/2014 09/14/2014 - 09/20/2014 09/21/2014 - 09/27/2014 09/28/2014 - 09/30/2014

perl

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -