0

I can get current date and time in yyyy/mm/dd format in powershell. I want the output of this cmd to be put in text file.

Currently Command I run is

get-date -format yyyy/mm/dd

Works as expected but I when I try to redirect output to file I see error

get-date -format yyyy/mm/dd - o test.txt

The question might be trivial as I am new to powershell

3 Answers 3

2

Use Out-File

get-date -format yyyy/mm/dd | Out-File -FilePath C:\Date.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Keep in mind that Out-File will overwrite the full contents of the file, unless you add the parameter -Append.
1
date -format yyyy/mm/dd >c:\date.txt

Overwrite txt file ^

date -format yyyy/mm/dd >>c:\date.txt

Append new line to txt file ^

Shorter and slightly more efficient method(s)

Comments

0

I am not sure if this is a recent change but mm is giving me minutes - I have had to use MM for months i.e.

date -format yyyy/MM/dd >> c:\date.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.