June 7th, 2016

PowerTip: Get the time and date as a string of numbers by using PowerShell

Doctor Scripto
Scripter

Summary: Use the –format option in Get-Date to change the output.

Hey, Scripting Guy! Question I’d like to build some log files and have the date and time as part of the name. Is there a way to show the date and time in a format where it’s all numbers?

Hey, Scripting Guy! Answer Absolutely! Just use the –format option with Get-Date and supply a format for the output. To see the format as month, day, year, hour, minutes, and seconds, use this example:

Get-Date –format ‘MM_dd_yyyy-HH_MM_ss’

The Doctor

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback