Date::Calc and a little hand rolled code may help:

use strict; use warnings; use Date::Manip; use Date::Calc qw(Add_Delta_DHMS); use Benchmark qw(cmpthese); Date_Init ("TZ=UT"); my @dates = ("2007-04-30 12:50:00", "2007-04-30 11:50:00"); print "Manip result: \n", join "\n", manip (), "\n"; print "Calc result: \n", join "\n", calc (), "\n"; cmpthese (-1, { manip => \&manip, calc => \&calc, }); sub manip { my @results; for (@dates) { my $date = $_; my $hour = (split /:/, $date)[0]; die "Can't find hour" unless $hour =~ /\s(\d{2})$/; if ($1 >= 12){ $date=DateCalc("$date","+24 hours"); ###Takes 2min out of +2:30min. $date=&UnixDate($date,"%Y-%m-%d"); } push @results, $date; } return @results; } sub calc { my @results; for (@dates) { my $date = $_; my $hour = (split /:/, $date)[0]; die "Can't find hour" unless $hour =~ /\s(\d{2})$/; if ($1 >= 12){ my ($year,$month,$day, $hour,$min,$sec) = $date =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS ( $year,$month,$day, $hour,$min,$sec, 1, 0, 0, 0 ); $date = "$year-$month-$day $hour:$min:$sec"; } push @results, $date; } return @results; }

Prints:

Manip result: 2007-05-01 2007-04-30 11:50:00 Calc result: 2007-5-1 12:50:0 2007-04-30 11:50:00 Rate manip calc manip 662/s -- -99% calc 59112/s 8825% --

A little tidying up to generate consistent output formating may be required, but that's likely not a big price to pay.


DWIM is Perl's answer to Gödel

In reply to Re: Changing dates by GrandFather
in thread Changing dates by snantz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.