Henry Wong wrote: > Ok, i've decided to skip using the Date::Manip coz its giving me lots of > problems. Is there a way to compare dates (e.g. Thu Jun 20 12:00:00 2002) > and sort them in order? What i've always wanted is to sort them, and > subsequently using User's input of Start & End date to capture relevant > logs as explained below. > > Assuming that $noforlines is the no of lines the log file has, and that > $convertedList[] contains the dates, while $user_start & $user_end > containing the user's desired start & end date, how do i compare dates? > The below coding doesn't seem to work right. > > for ($s=0;$s<$noforlines;$s++) { > if (($convertedList[$sian]>= $user_start)&&($convertedList[$sian]<= > $user_end)) { > open (USER, ">>${filename}_REQUEST.TXT"); > print USER "$convertedList[$sian]\t$inputList[$sian]\n"; > } > > Pls advise, thanks. > > Regards, > > ~ HENRY WONG ~
what problem do you have with Date::Manip? :-) I found it very easy to use. anyway, if you don't want to use Date::Manip, you can still sort/compare date/time. there are a couple ways(at least) of doing this: 1. compare the date/time as string. consider you have the following 2 dates: my $date1 = '2002-12-23 21:34:45'; my $date2 = '2002-12-21 09:08:12'; you can compare them like: if($date1 > $date2){ print "yes\n"; }else{ print "no\n"; } which we use it as string and compare it like a string. you must remember to make all of your dates the same exact format. if you don't, you will run into problem like: my $date1 = '2002-12-23 21:34:45'; my $date2 = '2002-2-23 02:34:12'; suddenly, $date2 is 'bigger' than $date1 but $date1 is Dec 2002 and $date1 is only Feb 2002. 2. another way is to convert the date string into seconds with Time::Local and localtime. when the user enter a date, convert it to seconds and then compare it with whatever you parsed from the log. i would recommand you using this method david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]