How to get yesterday's date with perl one-liner in MS windows?

Want to get yesterday's date with perl. One-liner is best.
Who is Participating?
tel2Connect With a Mentor Commented:
Or, slightly more concisely, you can use:
    perl -MPOSIX -e "print strftime('%m%d%Y',localtime time -86400)"
jl66Author Commented:
the date format is MMDDYYYY (8 numbers).
Hi jl66,

Is this what you're after:
    perl -MPOSIX -e "print strftime('%m%d%Y',localtime time -24*60*60)"
Output is:
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

jl66Author Commented:
tel2: thanks a lot for the tips.
The output is dY
What is wrong? Is it for MS windows?
tel2Connect With a Mentor Commented:
Yes, it is for MS Windows, and "04012011" is the output I got when I ran it on XP (the current date here is 2-April).

Please do this, and hopefully I will be able to help you:
1. Tell me, when you say dY, do you mean literally "dY", or is that the format of the date you are getting?
2. Copy one of the 2 solutions I gave you.
3. Paste it in to your Windows command line (Start > Run > cmd), and hit Enter.
4. Copy and paste the command you used back here, so I can see it.
5. Copy and paste the output here, so I can see it.
6. Copy and paste the output of this command here, so I can see it:
       perl -v

jl66Author Commented:
Tel2: On the server I ran perl was not installed well. I am OK now. The last question is that I tried to put the number in a file,
perl -MPOSIX -e "print strftime('%m%d%Y',localtime time -86400)" >c:\t.txt
but I got the error:
"Can't find string terminator "'" anywhere before EOF at -e line 1."
jl66Author Commented:
Thank you so much.
Glad to be of service, jl66.

I assume you're not getting the error anymore.  When I run the code you've pasted, it puts the date in the t.txt file without error.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.