1. Is there a way to get the system date using perl in the following format mm-dd-yyyy?

Yes, using POSIX::strftime:

print POSIX::strftime("%m-%d-%Y",localtime()),"\n";

2. is there a way to compare the dates to see which is greater or lesser then a given date which is in mm-dd-yyyy format?

Yes, using POSIX::mktime() and optionally POSIX::difftime():

my $start_date_string = '05-03-2003'; my @date_parts = split('-',$start_date_string); # build time my $then_time = POSIX::mktime( 0,0,0, $date_parts[1], ($date_parts[0] -1), ($date_parts[2] - 1900) ); ### or could be mktime() from another split string here my $now_time = time(); #could also use POSIX::difftime: #"the time difference (in seconds) between two times #(as returned by 'time()')" if( $then_time < $now_time ){ print POSIX::ctime($then_time) . " was before " . POSIX::ctime($now_time) . "\n"; }else{ print POSIX::ctime($then_time) . " was after " . POSIX::ctime($now_time) . "\n"; }

All that fun and POSIX comes with core perl.

Update:Oops, thanks rob_au for catching my typo.


cp
----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

In reply to Re: help on getting date by crouchingpenguin
in thread help on getting date by Anonymous Monk

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.