in reply to Find 30 days from today's date


perl -e "print scalar localtime (time - $ARGV[0] * 86400)" 30 #output: Wed Mar 19 12:34:19 2014
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Find 30 days from today's date
by BrowserUk (Patriarch) on Apr 19, 2014 at 18:36 UTC

    A couple of tweaks improve it somewhat:

    C:\test>perl -e "$x = scalar localtime (int(time()/43200)*43200 - $ARG +V[0] * 86400); substr($x,11,9,''); print $x" 30 Thu Mar 20 2014

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      eh eh quoting you is like a summoning spell..
      you burned me on time (appropriate analogy) BrowserUk .. i was thinking how to tweak it too.

      And if you are searching files newer than..? my oneliner skips all seconds between midnigth and the current second: this seems to be an headcache for anonymous. So i have tweacked this way:
      perl -MTime::Local -e " print scalar localtime (timelocal(0, 0, 0, @{[ +localtime(time - $ARGV[0] * 86400)]}[3..8]))" 30 #output Thu Mar 20 00:00:00 2014
      very lazy solution.

      HtH
      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^2: Find 30 days from today's date
by Anonymous Monk on Apr 18, 2014 at 21:22 UTC

    No. This gives the time 2592000 non-leap seconds ago.

    Sure, this code will be right most of the time, and it might even meet the OP's specs. However, it's lazy code like this that ignores the existing date/time modules which cause the subtle bugs that give people everywhere headaches. It's coding like this that causes people to ask questions like the original post in the first place.

      there are many ways to get the job done in Perl. I like this freedom as in 'free beer'
      It's up to the wisdom of the coder when choice a solution or another.
      In a critical application i would use some standard module about Date:: while in a oneliner maybe i would choice the simplest solution.

      I never propose me as 'The teacher' as you can guess looking at my nickname, maybe i need to add a standard disclaimer in the signature? ;=)

      can i cite BrowserUk as found here?
          On the basis of what I know, or at least what I think I know, I think this will help you, so here it is. It almost certainly isn't perfect, it may not even be relevant, though I believe it to be, and I am happy to offer it in case it helps, and to learn from the enevitable corrections that will come if what I believe is wrong.
      
      I think that this attitude is most succinctly and most prevelantly summed up by the oft-used sign-off HTH. -- Hope That Helps. 
      My best form of enjoy here at perlmonks is when i post something and many experienced or less monks, point me to some issue or better way to do it.

      Please let all solution to have the right to exist, the wisdom is in the coder not in the code.
      Cya

      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.