Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello Monks, I have a problem formatting my dates with DateTime module. This code:
use DateTime; use Date::Format; my $one_month_ago = DateTime->today->subtract(months => 1); print $one_month_ago = DateTime->last_day_of_month( month => $one_month_ago->month, year => $one_month_ago->year, )->strftime("%m%d%y"); my $start_date = DateTime->today->subtract( months => 1); print $start_date->strftime("%m%d%y");
returns the date in the formats that I want. (MMDDYY)
This code that I have with mechanize entering the information in fields on a website, however, gives me the start date as MMDDYYT00:00:00.
my $start_date = DateTime->today->subtract( months => 1); $start_date->strftime("%m%d%y"); print $start_date; my $end_date = DateTime->today->subtract(months => 1); $end_date = DateTime->last_day_of_month( month => $end_date->month, year => $end_date->year, )->strftime("%m%d%y"); print $end_date; #This block of code is intended to fill in the required forms $mech->get(""); my $usr = "asdf"; my $pw = "asdf"; $mech->form_number(1); $mech->field( "capsn", $usr); $mech->form_number(2); $mech->field("capsp", $pw); $mech->form_number(3); $mech->field( "startdate", $start_date); $mech->form_number(4); $mech->field( "enddate", $end_date); $mech->form_number(5); $mech->select("format", "2"); $mech->click();
Why is this happening? Thanks in advance for your input..

In reply to DateTime formatting problem by PerlSufi

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [1nickt]: \my %foo = { bar => 1 }; say $foo{bar};
    [Corion]: 1nickt: Would be great, especially for naming parameters in @_.
    [Corion]: When you pass an arrayref, you get to treat it like a local array. But then, I'm cautious with the experimental features, because just when I thought function signatures were a set thing, there is a proposal to use sub [ $foo, $bar ] { ... } to ...
    [Corion]: ... declare the parameters, instead of the more common sub ($foo, $bar) { ... }

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2017-11-17 20:40 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (272 votes). Check out past polls.