• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

Perl function that takes a number and returns a string (YYYYMMDD) of today's date minus the input number of days

Hopefully this is straightforward for a Perl wizard.  I'm sure the function is on the Web somewhere if I could find it.  I need a Perl function that does this (in pseudocode):

GetDateStamp(numDays)
{
    return (today - numDays) as YYYYMMDD
}

If I need to include a module or anything, that's fine; just let me know.

Thanks!
-Dave
0
JediBecker
Asked:
JediBecker
  • 2
  • 2
1 Solution
 
ozoCommented:
sub GetDateStamp{
my $time=time;
return  strftime"%Y%m%d",localtime $time+60*60*(12-(localtime$time)[2]-24*shift);
}
0
 
ozoCommented:
use POSIX;
sub GetDateStamp{
my $time=time;
return  strftime"%Y%m%d",localtime $time+60*60*(12-(localtime$time)[2]-24*shift);
}
0
 
JediBeckerAuthor Commented:
Perfect!
0
 
JediBeckerAuthor Commented:
Thanks, Ozo!  That's perfect.  However, when writing the question, I moronically forgot to include the stipulation that the days to subtract should be business days.  So it needs to take weekends into account.  Since you answered exactly what I asked, I graded that.  I'm going to post the same question with the business day requirements right now, if you are interested in helping with that, too.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now