Operating System - HP-UX
1753900 Members
7492 Online
108809 Solutions
New Discussion юеВ

Re: get date of last week with script

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: get date of last week with script

Hi (again):

> i want to change date format as below:
Mon May 3 10:42:43 2010 => 20100503

Use this:

# cat ./lastweek
#!/usr/bin/perl
use strict;
use warnings;
my $t = time();
my @t = localtime($t);
my $d = 7 + (@t)[6];
my $b = $t - ( $d * 86400 );
for ( 0 .. 6 ) {
$t = ( $b + ( $_ * 86400 ) );
@t = localtime( $b + ( $_ * 86400 ) );
printf "%s => %4d%02d%02d\n", scalar localtime($t), $t[5] + 1900,
$t[4] + 1, $t[3];
}
1;

...run as:

# ./lastweek
Sun May 2 11:01:06 2010 => 20100502
Mon May 3 11:01:06 2010 => 20100503
Tue May 4 11:01:06 2010 => 20100504
Wed May 5 11:01:06 2010 => 20100505
Thu May 6 11:01:06 2010 => 20100506
Fri May 7 11:01:06 2010 => 20100507
Sat May 8 11:01:06 2010 => 20100508

...

Please reopen this thread to assign points appropriately. See:

https://forums11.itrc.hp.com/service/forums/helptips.do?#41

https://forums11.itrc.hp.com/service/forums/helptips.do?#22

Regards!

...JRF...
Kyu-Yong Kwon
Frequent Advisor

Re: get date of last week with script

thanks a lot
James R. Ferguson
Acclaimed Contributor

Re: get date of last week with script

Hi (again):

> thanks a lot

I'm glad you're satisfied with the answers provided. The appropriate thing to do is to reopen this thread and assign points appropriately. See:

https://forums11.itrc.hp.com/service/forums/helptips.do?#41

https://forums11.itrc.hp.com/service/forums/helptips.do?#22

Regards!

...JRF...