[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Help !!! Easy perl question

I am using the stat function for date of a file however i get a result like -

966152578

i know this is in seconds. but how do i convert it into a readable date - Day , Month , Year

Anant
0
anant99
Asked:
anant99
  • 3
  • 2
  • 2
1 Solution
 
Kim RyanIT ConsultantCommented:
$file_date = 966152578;

$formatted_file_date=  localtime($file_date);
# returns a string: Sun Aug 13 17:42:58 2000
print $formatted_file_date;

# or to get all components, $mon will be in the range 0..1, where 0 is January
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($file_date);
0
 
bebonhamCommented:
anant99

please accept an answer in your question on optimization in the cgi area.

Bob
0
 
anant99Author Commented:
dear teraplane ,

but i want only day , month and year. not the rest

Anant

bebonham - i have accepted an answer
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
anant99Author Commented:
thanks

Anant
0
 
bebonhamCommented:
thanks anant, I didn't not mean that you should select mine, because I was clearly wrong, I was hoping you would have accepted Sapa's answer.

thanks for closing the question, however.
0
 
Kim RyanIT ConsultantCommented:
Taking an array slice will let you look at the 3 values only

($mday,$mon,$year) = (localtime($file_date))[3,4,5];
$year += 1900;
print "day: $mday month: $mon year: $year";
0
 
anant99Author Commented:
bebonham - i accepted your because of your home made recipe not because of the array stuff... As my question was about optimization and not array(array was juat an example).

teraplane - i figured that out. thanks anyway.

Anant
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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