Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

dates-unix <==> mm/dd/yyyy

by Blue_eyed_son (Sexton)
on Jul 16, 2005 at 23:44 UTC ( #475519=perlquestion: print w/ replies, xml ) Need Help??
Blue_eyed_son has asked for the wisdom of the Perl Monks concerning the following question:

Hi Everyone-
I am working on a project that involves searching a wide search window, but if I get too many results, I need to narrow the window.

Ideally, I'd like to convert the dates of the first search window into Unix format, break it into equal parts depending on the popularity of the search term (for example if it tells me there are 10,000 results, but only lets me see the first 1,000--so I would break it into at least ten equal search windows). Then increment the first unix date, and convert them both back into mm/dd/yyyy to post the search.

How should I go about doing this?

Can anyone recommend a reliable module if necessary?

Thanks,

Steve

Comment on dates-unix <==> mm/dd/yyyy
Re: dates-unix <==> mm/dd/yyyy
by graff (Chancellor) on Jul 17, 2005 at 00:17 UTC
    If just go to search.cpan.org, select "Modules" in the drop-down menu and put "Date::" in the search window, you'll get lots of solutions to choose from.

    For a bare-bones, core-modules-only way to convert dates from strings to unix "seconds-since-the-epoch" numbers, look up "perldoc -f localtime" for conversion of unix time to calendar numerics or string, and "perldoc Time::Local", whose "timelocal" function can convert calendar numerics to unix time.

    For more elaborate modules that do more for you and might make your job easier, consider Date::Calc or Date::Manip.

Re: dates-unix <==> mm/dd/yyyy
by itub (Priest) on Jul 17, 2005 at 00:33 UTC
    Also see the strftime in the POSIX module that comes with perl.
Re: dates-unix <==> mm/dd/yyyy
by brian_d_foy (Abbot) on Jul 17, 2005 at 04:26 UTC

    I like the DateTime module.

    #!/usr/bin/perl -l use DateTime; my $d1 = DateTime->from_epoch( epoch => time ); print "1. epoch: " . $d1->epoch; print "1. mm/dd/yyyy: " . $d1->mdy( '/' ); my $d2 = DateTime->new( month => 7, day => 16, year => 2005, ); print "2. epoch: " . $d2->epoch; print "2. mm/dd/yyyy: " . $d2->mdy( '/' );
    --
    brian d foy <brian@stonehenge.com>
Re: dates-unix <==> mm/dd/yyyy
by Paulster2 (Priest) on Jul 18, 2005 at 01:07 UTC

    The above are excellent suggestions. I prefer Date::Manip myself. It is a larger module, but it is also very well documented. I use the perldoc on it instead of the man pages for date to figure things out in Unix, just because it is so detailed. It will solve all of your date manipulation needs ... well most all of them anyway ;-)

    Paulster2


    You're so sly, but so am I. - Quote from the movie Manhunter.
Re: dates-unix <==> mm/dd/yyyy
by TedPride (Priest) on Jul 18, 2005 at 06:53 UTC
    The problem with doing things this way is that you require your search results to be evenly distributed throughout the entire date range. Also, since you have to count the results to arrive at the 10,000 number anyway, there's no real savings in adjusting the time segment and then searching again. Why not just return the first x number of search results, along with the ID of the last result? Then you can display the date range as being the range of the search results, and you can pick up your search from ID-1 (or ID+1, depending) if the user wants more results.

    As for actually converting to and from timestamps, see above.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://475519]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-04-16 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (430 votes), past polls