Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Help with time 2

by ACJavascript (Acolyte)
on Mar 26, 2003 at 02:23 UTC ( [id://245842]=perlquestion: print w/replies, xml ) Need Help??

ACJavascript has asked for the wisdom of the Perl Monks concerning the following question:

Hello again!
I am posting this as a 2 in a sense from my last post.. Dakkar gave me this code,, It worked great I was able to play with it,,, Now, As one of the users pointed out I did not have a year --- So i tried to put a year in and i keep getting an error,, I have been working this thing out for a day now, and I would love some help! :D

use POSIX; # this module defines the function mktime $last=$FORM{'userTime'}; # 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-$ +FORM{'timeControl'}); # a day ago ($mon2,$mday2,$wday2,$year2,$hr2,$min2,$sec2)=($last=~m|^(\d+)/(\d+)/( +\d+)/(\d+)/(\d+):(\d+):(\d+)|) or die "Wrong timestamp: $last\n"; # e +xtract values from the timestamp, with a bit of checking $year = $year + 1900; $last_time=POSIX::mktime($sec2,$min2,$hr2,$mday2,$mon2,$year2); # tran +s form the timestamp into a unix-time (seconds since the epoch) unless (defined $last_time) {die "Wrong timestamp2: $last\n$year, $yea +r2"} # mktime will return undef if the date is not valid

I keep getting the error on Timestamp2..

Thanks in advance!!!!

Replies are listed 'Best First'.
Re: Help with time 2
by MarkM (Curate) on Mar 26, 2003 at 05:25 UTC

    I suspect you are passing 2003 into $year2, making mktime() croak. Also, I don't see a reference above to adding one to $mon to make it be as expected.

    I would strongly suggest you store the raw timestamp value in $FORM{'userTime'}. This way, you don't need to parse it, or decode it. As long as you have control over userTime, this is safe.

Re: Help with time 2
by cfreak (Chaplain) on Mar 26, 2003 at 14:41 UTC

    I'm assuming this is a follow-up to a different post which I did not see so I'm not entirely certain what you are trying to do. However I can say that using Date::Calc or Date::Manip makes life much easier when doing any date or time related calculations.

    Lobster Aliens Are attacking the world!
      Hey thanks alot guys/gals.. Everthing seems to running smootly now!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://245842]
Approved by bart
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-07-13 07:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.