Dear Monks,
I am using a subroutine to calculate the time difference which is used to calculate the users last login time.
For example if the users ABCD lastlogin time is on 2013-08-15 HH:MM:SS,after that if ABCD is not logged in the system again it should display the same date and time as he last logged in. But it disaplying different time each time i run the script.
use Time::Local;
use POSIX qw(strftime);
$lastlogin = lastlogin(2);
sub lastlogin() {
my $count = shift;
mu $now_string = timelocal(localtime);
$n_days_ago = (60*60*24*$count);
$N_DAYS_EGO = $now_string - $n_days_ago;
$N_DAYS_EGO = strftime("%Y-%m-%d %H:%M:%S",localtime($N_DAYS_EGO ));
return $N_DAYS_EGO ;
}
If i call the subroutine with with some numeric values the date it is returinging is correct, but the time field is varying. For Ex if user has terminated on 10-04-2013:HH:MM:SS and he last logged is on 8-04-2013 than it should display the same date and time if we run the script even today, but i am getting the time field different than this, it leading to wrong login information.
Monks please suggest and guide me.
Thanks in advance.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.