Quantcast
Channel: Windows Archive - TechOverflow
Viewing all articles
Browse latest Browse all 17

How to generate filename with date and time in PowerShell

$
0
0

You can use Get-Date like this to generate a date that is compatible with characters allowed in filenames:

Get-Date -UFormat "%Y-%m-%d_%H-%m-%S"

Example output:

2020-12-11_01-12-26

In order to generate a complete filename, surround that with $() and prepend/append other parts of your desired filename:

mysqldump-$(Get-Date -UFormat "%Y-%m-%d_%H-%m-%S").sql

 


Viewing all articles
Browse latest Browse all 17

Trending Articles