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("https://caps.usps.gov/ssl_caps/caps_ai.asp");
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..
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.