Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Custom date calculations using Date::Manip

by cavac (Parson)
on Nov 27, 2019 at 17:57 UTC ( [id://11109316]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/env perl
    
    use strict;
    ...
    }
    
    print $outstring, "\n";
    
  2. or download this
    #!/usr/bin/env perl
    
    use strict;
    ...
    
    my $date = Date::Manip::Date->new();
    $date->parse('2019-07-31');
    
  3. or download this
    my $month = $date->printf('%m');
    $month =~ s/^0+//g;
    my $dayofyear = $date->printf('%j');
    ...
    my $dayofmonth = $date->printf('%d');
    $dayofmonth =~ s/^0+//g;
    my $year = $date->printf('%Y');
    
  4. or download this
    # December starts on 1st of September...
    my $septstart = Date::Manip::Date->new();
    $septstart->parse($year . '-09-01');
    my $septday = $septstart->printf('%j');
    $septday =~ s/^0+//g;
    
  5. or download this
    my $outstring = '';
    if($month == 8) {
        # August
        $outstring = ordinate($dayofmonth) . ' August ' . $year;
    
  6. or download this
    } else {
        # December
        if($month > 8) {
            my $daycount = $dayofyear - $septday + 1;
            $outstring = ordinate($daycount) . ' December ' . $year
    
  7. or download this
        } else {
            # Uh-oh, this is the continuation of last years december...
            my $decend = Date::Manip::Date->new();
    ...
            $outstring = ordinate($daycount) . ' December ' . $year
        }
    }
    
  8. or download this
    print $outstring, "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://11109316]
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found