CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
testing for dates later than..

 



jacqui
Novice

Jun 3, 2000, 1:06 PM

Post #1 of 2 (363 views)
testing for dates later than.. Can't Post

 
Hi,

Can anyone PLEEEEZE tell me how to find if one date is before or after another.

I want to be able to extract and view sections of my server log by inputing a start and end date.

I've managed to sort out everything except this bit and cannot find anything about it in my books or the on-line tutorials I've found.

Thanks

Jaq

xxxx


DrZed
User

Jun 3, 2000, 2:48 PM

Post #2 of 2 (363 views)
Re: testing for dates later than.. [In reply to] Can't Post

Well, one way would be to extract the elements of the date and convert them into something which can be used in a comparison.

Note, I am very much a novice to Perl. I know how to write a lot of code, but there's a good chance that there's a 'better' way to do what I do. However, something like the following would work:

If your date format is like this:
$date = "02/Jun/2000:22:12:58"

Then you could do:
$date =~ m|(\d\d)/(\w\w\w)/(\d\d\d\d) : (\d\d) : (\d\d) : (\d\d)|;
# Note: don't put spaces around the :'s. They are there to eliminate the 'smilies'.
$day = $1; $mon = $2; $yea = $3;
$hou = $4; $min = $5; $sec = $6;

'Jan01Feb02Mar03Apr04May05Jun06Jul07Aug08Sep09Oct10Nov11Dec12' =~ m|$mon(\d\d)|;
$mon=$1;

$datevalue = $year.$mon.$day.$hou.$min.$sec;

You know have a variable ($datevalue) which you can compare. It's simply all of the digits in the order of their significance. The value itself isn't relivant, other than the fact that the value of earlier dates will be less than later dates.

For example, 02/Jun/2000:22:12:58 would become 20000602221258. Any later dates would have a greater value, and earlier dates would have a lesser value.

How exactly you do things depends on the specifics of your program.

Dr. Zed

[This message has been edited by DrZed (edited 06-03-2000).]

[This message has been edited by DrZed (edited 06-03-2000).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives