in reply to Between Two Times??? Help!
Where does that strange date format come from? It's the first time I see a date with "day of the week" but without the year...
Anyway.
About your code: the two arrays are useless, since $days[$n]==$n for each $n, and the same holds for @Months. And keep in mind that @array[@indices] is an array slice, while $array[$index] is a single element. Search for "array slice" for more info.
Now, what do you really need to do? Do something if the current time is no later than 24 hour after a given date?
In this case, I'd do it this way:
use POSIX; # this module defines the function mktime $last='2/21/5/19:22:14'; # this is the timestamp of the user's last lo +gin $now=time; # the present ($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now-8 +6400); # a day ago ($mon2,$mday2,$wday2,$hr2,$min2,$sec2)=($last=~m|^(\d+)/(\d+)/(\d+)/(\ +d+):(\d+):(\d+)|) or die "Wrong timestamp: $last\n"; # extract values + from the timestamp, with a bit of checking $last_time=POSIX::mktime($sec2,$min2,$hr2,$mday2,$mon2,$year); # trans +form the timestamp into a unix-time (seconds since the epoch) unless (defined $last_time) {die "Wrong timestamp: $last\n"} # mktime +will return undef if the date is not valid print "In range" if ($now-$last_time)<86400; # if the difference is le +ss than a day...
-- dakkar - Mobilis in mobile
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Between Two Times??? Help!
by ACJavascript (Acolyte) on Mar 22, 2003 at 17:00 UTC |
In Section
Seekers of Perl Wisdom