Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How to get after 4 and 5 days date from today date

by sureshrps (Novice)
on Feb 15, 2011 at 15:33 UTC ( [id://888270]=perlquestion: print w/replies, xml ) Need Help??

sureshrps has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I need one help. I need to find after 5 days date from today date. then need that output date plus 4 days date. I am waiting for your valuable response. Regards Suresh Kumar. P
  • Comment on How to get after 4 and 5 days date from today date

Replies are listed 'Best First'.
Re: How to get after 4 and 5 days date from today date
by moritz (Cardinal) on Feb 15, 2011 at 15:34 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How to get after 4 and 5 days date from today date
by Ratazong (Monsignor) on Feb 15, 2011 at 15:39 UTC

    In addition to the good answer from moritz:

    I prefer Date::Calc for all my Date-calculations. It may be overhead in your case, but I like the idea of having only one Date-module to learn ;-) Date::Calc offers a function called Add_Delta_Days which serves your purpose.

    HTH, Rata

    Update:WOW! I thought I was pretty fast with typing my answer ... but 5 monks were faster! I'm impressed!

Re: How to get after 4 and 5 days date from today date
by toolic (Bishop) on Feb 15, 2011 at 15:35 UTC
Re: How to get after 4 and 5 days date from today date
by kennethk (Abbot) on Feb 15, 2011 at 15:37 UTC
Re: How to get after 4 and 5 days date from today date
by fisher (Priest) on Feb 15, 2011 at 15:38 UTC
    sleep (5*24*60*60); my $after5date = localtime(time); print $after5date; sleep (4*24*60*60); my $after4days = localtime(time); print $after4days;
    NB: sorry, this is a joke

      Not all days have 24 hours. Fix below. This will also give you the answer up to 23.5 hours sooner.

      use POSIX qw( strftime ); sub next_day { my $start_d = (localtime)[3]; for (;;) { sleep(30*60); my $d = (localtime)[3]; return if $d != $start_d; } } next_day() for 1..5; print strftime("%Y-%m-%d\n", localtime()); next_day() for 1..4; print strftime("%Y-%m-%d\n", localtime());

      Suffers from a race-condition that manifests itself if the loops is started very shortly before midnight.

Re: How to get after 4 and 5 days date from today date
by blakew (Monk) on Feb 15, 2011 at 15:39 UTC
    With Date::Calc you could try Add_Delta_Days:
    Add_Delta_Days ($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);
Re: How to get after 4 and 5 days date from today date
by ikegami (Patriarch) on Feb 15, 2011 at 16:13 UTC
    I use DateTime.
    my $dt = DateTime->today( time_zone => 'local' ); $dt->add( days => 5 ); print $dt->ymd(), "\n"; $dt->add( days => 4 ); print $dt->ymd(), "\n";

      I prefer this.

      Check for Date::Time documentation for some more methods.

Re: How to get after 4 and 5 days date from today date
by sundialsvc4 (Abbot) on Feb 15, 2011 at 18:28 UTC

    My personal favorite is Date::Manip ... but the real point here is that there are several good modules already out there for doing date/time manipulation.   If, for example, what you want is “five business days from now, excluding the legal holidays of Croatia,” then there is probably a CPAN routine out there now which will do it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://888270]
Approved by wfsp
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found