in reply to help on getting date
1. Is there a way to get the system date using perl in the following format mm-dd-yyyy?
Yes, using POSIX::strftime:
print POSIX::strftime("%m-%d-%Y",localtime()),"\n";
2. is there a way to compare the dates to see which is greater or lesser then a given date which is in mm-dd-yyyy format?
Yes, using POSIX::mktime() and optionally POSIX::difftime():
my $start_date_string = '05-03-2003'; my @date_parts = split('-',$start_date_string); # build time my $then_time = POSIX::mktime( 0,0,0, $date_parts[1], ($date_parts[0] -1), ($date_parts[2] - 1900) ); ### or could be mktime() from another split string here my $now_time = time(); #could also use POSIX::difftime: #"the time difference (in seconds) between two times #(as returned by 'time()')" if( $then_time < $now_time ){ print POSIX::ctime($then_time) . " was before " . POSIX::ctime($now_time) . "\n"; }else{ print POSIX::ctime($then_time) . " was after " . POSIX::ctime($now_time) . "\n"; }
All that fun and POSIX comes with core perl.
Update:Oops, thanks rob_au for catching my typo.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: help on getting date
by rob_au (Abbot) on Jun 03, 2003 at 06:12 UTC |