in reply to How to get the current Date and Time using Perl on windows?

In the windows world, the date command is generally used for setting the date.

If you want a human-readable date/time stamp, then probably the simplest way is to use localtime.

For example:

C:\>perl -le "print scalar localtime" Wed Jan 2 15:27:20 2008

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^2: How to get the current Date and Time using Perl on windows?
by goibhniu (Hermit) on Jan 02, 2008 at 21:32 UTC

    As everyone has pointed out, there are much better, more perlish ways to do it, but here my $0.02 in the interest of TIMTOWTDI in case you're in a DOS batch file mindset.

    First, date /? reports:

    Displays or sets the date. DATE [/T | date] Type DATE without parameters to display the current date setting and a prompt for a new one. Press ENTER to keep the same date. If Command Extensions are enabled the DATE command supports the /T switch which tells the command to just output the current date, without prompting for a new date.

    If Command Extensions are missing, you can pipe the ENTER like this:
    echo.|date

    which is a little harder to parse, but also doesn't require setting the date.

    C:\chas_sandbox>perl -le "print `date /T`" Wed 01/02/2008 C:\chas_sandbox>perl -le "print `echo.\|date`" The current date is: Wed 01/02/2008 Enter the new date: (mm-dd-yy) C:\chas_sandbox>


    I humbly seek wisdom.
      The problem with this is that the OP was after a date and time stamp, and the DOS date command only gives the date. You could I suppose use a combination of both the date and time commands, but that would be just silly™

      Obviously, the OP has a script that was written for a *nix environment and he is trying to port it to winders.

        touchée. What version of ACME::ESP are you runing? Mine seems out of date (no pun intended; well, ok, maybe intended a little ;) ).


        I humbly seek wisdom.