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

Re: Comparing Dates With a Twist

by growlf (Pilgrim)
on Nov 01, 2001 at 07:05 UTC ( [id://122488]=note: print w/replies, xml ) Need Help??


in reply to Comparing Dates With a Twist

Hi Gus.

Maybe I am way out in left field here, but if you are talking database, and you are probably using DBI to access it.. (such as DBD::CSV http://www.perldoc.com/perl5.6.1/lib/DBD/CSV.html) why not just use the SQL functions to query for exactly what you want? Perhaps even make the DB query a sub that takes a date-delta as an argument that it will embed in the prepared query.

An extremely quick (and overly simplistic) example SQL statement that might do the trick for you is:
select mydatefield, myvaluestuff from mytable where mydatefield between (CURRENT_DATE)-90 and CURRENT_DATE
But, please be aware that I did not protect the date type in that query. You will need to determine more what you want to do in your query, what DBD to use, and use the apropriate functions in SQL.

Optionaly, you could also use the other SQL functions to parse a partial date field if the data is not actually stored as a date in the file (i.e. your date is in it's own field) such as to_date and date_part.

You might also gain some additional advantages by using DBI if you are not already doing so on your flatfile db.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-28 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found