On Tue, Jun 26, 2001 at 10:53:12PM -0500, Steve Howard wrote:
> I would suggest using the localtime function. That will work regardless of
> OS.
> 
> ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
> localtime(time);
> ($mon, $year) = ($mon+1, $year+1900);

That doesn't quite work, since %m and %d zero-pad their values.  If
you just need the date in one variable, call localtime as above, then
use sprintf to format them correctly:

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  localtime(time);
$current_date = sprintf("%d%02d%02d", $year+1900, $mon+1, $mday);

> If, however, you must drop a command through to the shell to pull a date
> from NT, the commands for date, and time are:
> 
> date /t
> time /t

I'd strongly recomment against that, both from a security and
performance point of view.  Why go out to the shell for something you
can do more easily, securely, and efficiently in Perl itself?

Walt

Reply via email to