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!

Formating Dates using HTTP::Date

Status
Not open for further replies.

ErrolDC2

MIS
Apr 6, 2005
43
US
I have a simple script that I need to return the timestamp of files as YYYY-MM-DD. Im using HTTP::Date but it's returning more than I need. Is there a way to further format the date easily?

Code:
#!/usr/bin/perl -w
use File::stat;
use Time::localtime;
use Time::Zone;
use HTTP::Date qw(parse_date time2str);



chomp(@ARGV = <STDIN>) unless @ARGV;
for ( @ARGV )
{
 $date_string = parse_date(ctime(stat($_)->mtime));
  print "file $_ updated at $date_string\n";
}

Thanks..
 
what is it returning? can you not use the substr command?

Code:
$date_string = substr(parse_date(ctime(stat($_)->mtime)),[b]start_position[/b],10);

substituting start_position with the correct number where the first char of the date starts and remembering that the logic start at position ZERO! for the first char.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
thanks for your help. im just an add hoc perl person so i never considered parsing the substr.

thanks again for your help.
 
no probs

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top