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.
jl66Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jl66Author Commented:
the date format is MMDDYYYY (8 numbers).
0
tel2Commented:
Hi jl66,

Is this what you're after:
    perl -MPOSIX -e "print strftime('%m%d%Y',localtime time -24*60*60)"
Output is:
    04012011
0
tel2Commented:
Or, slightly more concisely, you can use:
    perl -MPOSIX -e "print strftime('%m%d%Y',localtime time -86400)"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jl66Author Commented:
tel2: thanks a lot for the tips.
The output is dY
What is wrong? Is it for MS windows?
0
tel2Commented:
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

Thanks.
0
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."
0
jl66Author Commented:
Thank you so much.
0
tel2Commented:
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.

Later.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.