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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using time ranges to find data

Status
Not open for further replies.

ITadvice

IS-IT--Management
Jul 22, 2008
38
US
I have a form that allows users to select data for a certain time range. What module do I use to find data that is stored in text files? The files are saved according to the date of the information (yymmdd). Each file contains data for a certain time period. For example, someone may want to view data from 8:00 July 28 - 16:00 July 31. I first have to find the files within the date range and then collect the data that falls within the time range. How would I go about doing this?
 
Have a look at Date::Calc, I don't remember it has time capabilites.
 
Hello,

If you are programming in C++, you can use this:

time_t rawtime;
struct tm *timeinfo; //Create a structure for system time
// Get system time
time (&rawtime);
timeinfo = localtime(&rawtime);
cout<<asctime(timeinfo)<<endl;
 
I gotta ask.. why in the world would you provide a C++ answer in a perl forum?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
The date shouldn't be hard because of the naming of the file.
$range1 = '20080401';
$range2 = '20080501';
if ($file >= $range1 && $file <= $range2) {
print "$file!\n";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Travs69,

In your example, how would I know which files to open? Would I write my open command like this?
Code:
open($file, $range1 && $range2);

I was going to put all of the files into an array and then sort out the data that was in the specified time range.
 
Given that you have data in a whole bunch of files, and it's in text format, it means that every time your users want to select it you have a massive I/O overhead while you identify the files and then trawl through them.

You would be far better off putting this data into a relational database, and extracting the date and time out to a datetime column. An index on this column would allow you to retrieve the data very simply and quickly. Plus, SQL has a number of useful constructs for dealing with date ranges, like BETWEEN.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Unfortunately I am not able to use SQL. Any other suggestions on how to open multiple files between within a date range?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top