Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

by gods
on Feb 11, 2000 at 00:06 UTC ( #3333=superdoc: print w/replies, xml ) Need Help??
Hey runrig, thanks for the reply!

Cool, good info there, thanks!

I don't know if its the "best" way to go, but I was using the dates I created using the "Time::Piece" Module, then
I use the "Date::Manip" module to calculate a future date/time (*or past date if you needed to). The cool thing about
the Date::manip Module is that you can use human relate-able strings to calculate the date.

For example, before I added the "Date::Manip" Module, and currently still, I have a Command Line Option that the user inputs when
executing. Where the value of the argument is in the form of "a number followed by a time-unit". So for instance the
user could enter any of the following:
        --end-in="1hour"
        --end-in="2 hours"
        --end-in="3 hrs"
        --end-in="20 min"
        --end-in="30minutes"
        --end-in="1day"
        etc...............

Then after the user executes and after some error checking of the users input, I take the option the user entered, like "30 mins"
and then use that in the DateCalc Function, which is part of the Date::Manip Module. For the error checking I split the users
input into a number and a "time_unit", so "30mins" would get split into "30" and "mins", then I check each one.

So I would then take the current_date calculated by "Time::Piece qw(localtime)" and use that as the first argument to the "DateCalc"
Function, like so:
## Create the 'date manipulation' string for the DateCalc Function: # *The user's input is called $end_timeSpan... my $date_manip = "in $end_timeSpan" # For this example lets say: # $current_time == "07/17/2013 10:30:00" ### Calculate the future date from the $current_date: # *Output from function is in the form: # "2013071811:00:00" --> YYYYMMDDHH:MM:SS my $future_date = DateCalc($current_date,$date_manip) # After running the above & capturing each piece from DateCalc, the # $future_date == "07/17/2013 11:00:00", which would be 30 mins # from the $current_date.

So that's basically what I'm doing with the Date stuff. There is some other stuff I do with the Date and Time but that above is
the most important part.

Thanks again for all the suggestions and info.


Thanks Again,
Matt



In reply to Re^4: What's "Better" DateTime or localtime? by mmartin
in thread What's "Better" DateTime or localtime? by mmartin

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, 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2016-10-01 22:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How many different varieties (color, size, etc) of socks do you have in your sock drawer?






      Results (9 votes). Check out past polls.