Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

How to find if a certain time stamp is within a time period?

by dr.jekyllandme (Sexton)
on Aug 22, 2012 at 02:16 UTC ( #988923=perlquestion: print w/replies, xml ) Need Help??
dr.jekyllandme has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I want to figure out if a file's creation date is in between a certain range of time. For example let's say that I only want files that were created between June 1, 2011 and June 1, 2012. So far I have the time created but do not know how to proceed. Here is my code:
#!usr/bin/perl use strict; use warnings; use File::stat; my @files= <>; # Slurp list of files given in a file in cmd line foreach( @files ) { print; chomp; my($month, $year) = ( localtime( stat($_)->ctime ) )[4,5]; $year += 1900; print "$month $year\n"; # if $month, $year are within June 2011 and June 2012 do something }
I've been Googling this but haven't gotten a straight answer or I am just confused. If anyone can nudge me in the right direction, it would be great. Thank you.

Replies are listed 'Best First'.
Re: How to find if a certain is within a time period?
by BrowserUk (Pope) on Aug 22, 2012 at 02:27 UTC

    Does this help?

    print scalar localtime( 1306882800 );; Wed Jun 1 00:00:00 2011 print scalar localtime( 1338505200 );; Fri Jun 1 00:00:00 2012

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: How to find if a certain time stamp is within a time period?
by aitap (Deacon) on Aug 22, 2012 at 07:36 UTC

    One of the methods is to use Date::Parse to get the UNIX timestamps (in seconds) of the dates and compare them. Another is to use Date::Calc.

    Sorry if my advice was wrong.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://988923]
Approved by ww
and all is calm...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-05-26 03:49 GMT
Find Nodes?
    Voting Booth?