Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Offset POSIX qw(strftime)

Status
Not open for further replies.

Nova980

Technical User
May 20, 2009
40
US
I'm trying to offset %W by 4 weeks and I'm unable to get it done. Can someone help me please? TY

Code:
#!/usr/bin/perl

use POSIX qw(strftime);

our $today  =  strftime("09%m%%W%d", localtime);

foreach my $file (<AC*.lkp.z>) {
   rename ($file, "AC$today.lkp");
   last; # so we only rename 1 file
 
our $today = strftime("09%m%%W%d", localtime((60*60*24*7*4));

put a negative sign if you want it 4 weeks in the past:

our $today = strftime("09%m%%W%d", localtime(-(60*60*24*7*4));




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I think I made a boo-boo in my code above.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I think so too it fails to execute on the newline you created
 
What is the date format you want $today to be?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
This should do it:

Code:
$today = strftime("09%m%W%d", localtime(time()-60*60*24*7*4));

Probably a bad idea to hard-code 09?

Annihilannic.
 
At least with the Y2K problem we had many years warning to deal with it. As Annihilannic points out, this code will probably be broken in less than 6 months.
Although you could use "%y" to give you the two digit year (modulus 100) I have to wonder why you don't just use the entire 4-digit year.



Trojan.
 
Thanks for your help guys... I really appreciate your answers. Your wondering has given you the answer... I want it to break in six months. Thanks again!
 
Nova980 said:
I want it to break in six months
I guess we all have our own ways of ensuring our contracts get renewed... [smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top