date conversion in perl -


i using perl access db getting date in dd-mon-yyyy format. need perform 2 operations:

  1. convert format mm/dd/yyyy format.
  2. compare date 2 dates see if lies in time range.

    my $chdate = '15-feb-2013';

    sub get_stats {

    my %map = ( 'jan' => '01', 'feb' => '02', 'mar' => '03', 'apr' => '04',             'may' => '05', 'jun' => '06', 'jul' => '07', 'aug' => '08',             'sep' => '09', 'oct' => '10', 'nov' => '11', 'dec' => '12');      $chdate =~ s/(..)-(...)-(....)/$map{$2}\/$1\/$3/;     print "new date: $chdate"; 

    }

how perform (2) operation?

i have old version of perl (no time::piece module), not have privileges update :)

for (2) can this:

sub dateasnumber # arg mm/dd/yyyy - converts number compared {    $_[0]=~m%(\d\d)/(\d\d)/(\d\d\d\d)%;    return (($3 * 400 + $1) * 40 + $2); }  $test = &dateasnumber($testdateasstring);  if (&dateasnumber($startdateasstring) < $test &&     &dateasnumber($enddateasstring) > $test) {    print "$test date between $startdateasstring , $enddateasstring\n"; } else {    print "$test date not between $startdateasstring , $enddateasstring\n"; } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -