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

Doctor Scripto

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

0 comments

Discussion is closed.

Feedback usabilla icon