I have 2 sub
sub get_date { # -------------------------------------------------------- # Returns the date in the format "Mmmm dd, yyyy hh:mm ". # Warning: If you change the default format, you must also modif +y the &date_to_unix # subroutine below which converts your date format into a unix t +ime in seconds for sorting # purposes. my ($time) = @_; ($time) || ($time = time()); my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $day +light) = localtime($time); ($day < 10) and ($day = "0$day"); $mon += 1; ($mon < 10) and ($mon = "0$mon"); $year = $year + 1900; if ($min < 10) { $min = "0" . $min; } return "$mon\/$day\/$year $hour:$min:$sec"; } sub date_to_unix { my ($date) = @_[0]; my ($time); my ($mon, $day, $year) = split(/\//, $_[0]); my ($hour, $min, $sec) = split(/:/, $_[0]); unless ($day and $mon and $year) { return undef; } use Time::Local; eval { $mon = int($mon) - 1; $ +day = int($day); $year = int($year) - 1900; $time = timelocal($sec,$mi +n,$hours,$day,$mon,$year); }; if ($@) { return undef; } # + Could return 0 if you want. return ($time); }
I am using flat file database:
SN|Startdate|Completedate|Status
1234ABC|09/23/2003 14:30|09/30/2003 10:00|Completed
If I want to check for the running time I should change starttime and complete time to epoch and tell me days, hrs, min but why when I use sub datetounix it only count how many day like 09/30 - 09/23 = 7 days Could you help me to fix my sub datetounix. Thanks

Edit by thelenm: put <code> tags around code


In reply to date time to unix by britney

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.